Jump to content

Why ! str_replace


egturnkey

Recommended Posts

Hello friends,

 

If we have link

 

$x = "search engin";
<a href="google.com"><?=$x?></a>

 

and we want to remove space btween (search engine) to be (search-engine)

 

ineed we should use str_replace

and we change the link to

 

$manal = str_replace(" ", "-", trim($x));
<a href="google.com"><?=$manal?></a>

 

It not working ? and only working if

 

$manal = str_replace(" ", "+", trim($x));

 

why + not - ? and is there anyway else to replce space to - ?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/219464-why-str_replace/
Share on other sites

:wtf: i found the reason !

 

my example above it very simple but the real one has

 

keyword-ID

and if the keywords = x y z

and i replace space with - so the link will be

x-y-z-ID <-- works

 

but for .htaccess

 

RewriteRule -(.*)\.htm view.php?id=$1 <--- will not work

RewriteRule _(.*)\.htm view.php?id=$1 <--- will work

so the link will be

x-y-z_ID <--- Fine enough  :D

 

Now another quetions please what for multi-str replace

 

i mean if i've

 

$x= "I love?world";

i want replce both spaces and ? with - so it be

I-love-world

 

r_replace(array(" ","?"), "-", trim($x)); <-- it is right  :shrug:

Link to comment
https://forums.phpfreaks.com/topic/219464-why-str_replace/#findComment-1137938
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.