PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Apr 16, 2008 9:36 am
Use str_replace().
url_encode() might be a better option though, but it doesn't do what you're asking for.
nicosns
Forum Newbie
Posts: 21 Joined: Thu Jun 21, 2007 1:53 pm
Post
by nicosns » Wed Apr 16, 2008 9:39 am
onion2k wrote: Use str_replace().
url_encode() might be a better option though, but it doesn't do what you're asking for.
How can I use this with
?? I'm not a PHP expert, so if someone want to post the solution, many thanks!
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Apr 16, 2008 9:55 am
nicosns wrote: onion2k wrote: Use str_replace().
url_encode() might be a better option though, but it doesn't do what you're asking for.
How can I use this with
?? I'm not a PHP expert, so if someone want to post the solution, many thanks!
I know this is a bit of a crazy 'out there' idea, but you could try learning..
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 16, 2008 9:56 am
FYI, you'll rarely get someone on these boards to "post the solution". We prefer to help you help yourself.
Look at the documentation for
str_replace() - it's pretty straightforward.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
nicosns
Forum Newbie
Posts: 21 Joined: Thu Jun 21, 2007 1:53 pm
Post
by nicosns » Wed Apr 16, 2008 10:08 am
I understand, and I want to learn from a solution. I tried alot of things with the code, but I always get an error. Maybe today is my lucky day?
nicosns
Forum Newbie
Posts: 21 Joined: Thu Jun 21, 2007 1:53 pm
Post
by nicosns » Wed Apr 16, 2008 10:46 am
I got now this (not working offcourse
)
Code: Select all
<?php $replace = str_replace(" ", "-", "<?= htmlentities($_GET['q']) ?>"); echo $replace; ?>
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 16, 2008 10:55 am
Take out the <?= ?> around your htmlentities() call. You're already in a PHP block, you can't/don't need to open another one.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
nicosns
Forum Newbie
Posts: 21 Joined: Thu Jun 21, 2007 1:53 pm
Post
by nicosns » Wed Apr 16, 2008 11:05 am
pickle wrote: Take out the <?= ?> around your htmlentities() call. You're already in a PHP block, you can't/don't need to open another one.
Code: Select all
<?php $replace = str_replace(" ", "-", "htmlentities($_GET['q'])"); echo $replace; ?>
Now it gives me the error
Code: Select all
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/...
nicosns
Forum Newbie
Posts: 21 Joined: Thu Jun 21, 2007 1:53 pm
Post
by nicosns » Wed Apr 16, 2008 11:09 am
I found the solution
Code: Select all
<?php $replace = str_replace(" ", "-", "$_GET[q]"); echo $replace; ?>
Thanks!
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 16, 2008 11:22 am
htmlentities() is a function - don't quote it.
Putting single quotes around array keys when the array is in double quotes will give you that error.
Also, posting your PHP code in
tags rather than
tags makes it much easier to read & pick out possibly syntax errors.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.