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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.