gdfhghjdfghgfhf Posted April 9, 2008 Share Posted April 9, 2008 ok well i have a variable that includes a bunch of words exemple: "black cat blue fish brown dog brown horse black dog" i.e. i want to take out the words "brown dog"... these 2 words have to be next to each others and can be located anywhere in the string which one should i use? preg_replace or str_replace? could anyone give me an example how i can do that? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 9, 2008 Share Posted April 9, 2008 str_replace Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted April 9, 2008 Author Share Posted April 9, 2008 could you give me an example plz? i'm newbie with the syntax thing... and btw what is the difference between preg_ and str_ ? Quote Link to comment Share on other sites More sharing options...
awpti Posted April 9, 2008 Share Posted April 9, 2008 To expand upon the above answer (which is quite correct): 1.) preg_replace is slower (memory and cpu expensive) compared to str_replace 2.) If you know exactly what you're replacing and with what - str_replace is easier ex: str_replace("my_string", "my_replacement_string", "this is my_string"); would produce: this is my_replacement_string regex is a search pattern. You aren't searching if you know what must be replaced. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.