ad box 728 x 90
ad box 468 x 60
Hardware, Software, Code, PHP, ASP, Games, Reviews and Other Funky Stuff
Subscribe

Enter your email address:

Pic of the Month
Popular Posts

using str_replace() in php

code

it looks pretty easy really using str_replace in php, all it does is search a text string for all or a number of instances of the text or character that you want to replace and then replaces it with the text you specified.

basic usage:

str_replace ( text_search_for, text_to_replace_with, the_string_applied_to )

example:

$moo = str_replace("moo", "cow", "lick me in the moo");
echo $moo;

will output lick me in the cow

you can also pass a count number, to get a count of the amount of times the search string is found

$moo = str_replace("moo", "cow", "lick me in the moo",$numb);
echo $numb;

will echo 0 (hopefully) ;)

For further reading on this function here is a link to the full manual of str_replace().

Post Tags

This entry was posted on Friday, March 5th, 2010 at 11:48 pm and is filed under Featured. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Spam Protection by WP-SpamFree