TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   remove from string... how to do? (http://www.talkphp.com/absolute-beginners/1592-remove-string-how-do.html)

Sam Granger 12-04-2007 07:49 AM

remove from string... how to do?
 
Lets say I have a string with the following content:
Quote:

[rightimage]imagename.jpg[/image]Hello this is a test[image]hello.jpg[/image][image]chimp.jpg[/image]Cool! [image]cool.jpg[/image]
How can I make PHP search for the tags (image and rightimage) and remove them ant the contents so I'm left over with:
Quote:

Hello this is a testCool!
Thanks for looking!

SOCK 12-04-2007 07:53 AM

Are we assuming the string will always be the same, e.g. some text embedded within image tags with image names?

Use a regular expression to weed out anything between and including the opening and closing [ image ] tags.

Sam Granger 12-04-2007 08:17 AM

Quote:

Originally Posted by SOCK (Post 5216)
Are we assuming the string will always be the same, e.g. some text embedded within image tags with image names?

Use a regular expression to weed out anything between and including the opening and closing [ image ] tags.

Thanks!

Like so?

PHP Code:

$searchfor = array(
    
'#\[rightimage\](.*?)\[/rightimage\]#',
    
'#\[image\](.*?)\[/image\]#'
);
$replacewith = array(
    
'',
    
''
);
return 
preg_replace($searchfor $replacewith$text); 



All times are GMT. The time now is 09:00 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0