Faqts : Computers : Programming : Languages : PHP : Common Problems : Regular Expressions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

15 of 17 people (88%) answered Yes
Recently 4 of 6 people (67%) answered Yes


How can I get everything that IS NOT the word "sentence", from the string "This is a sentence."

Aug 24th, 2000 21:10
Ben Udall, Adam Daniel, http://www.php.net/manual/function.str-replace.php

You could use regular expressions and ereg_replace() to do this.  
However, the str_replace() function is faster and more versitile with 
simple search and replace applications.
$str = "This is a sentence.";
$new_str = str_replace("sentence", "", $str);
$new_str should now equal "This is a ."