eRott Posted April 27, 2008 Share Posted April 27, 2008 Hey there, Okay, I'm not too familiar with exactly how preg_replace works, so someone's help would be very much appreciated. I have a string lets go with: $message = "Hello dolly! [youtube]http://youtube.com/watch?v=eBGIQ7ZuuiU[/youtube]"; How would I go about stripping/cleaning: from that message? Thank you. Best Regards, Link to comment https://forums.phpfreaks.com/topic/103186-solved-preg_replace-strip_tags/ Share on other sites More sharing options...
dezkit Posted April 27, 2008 Share Posted April 27, 2008 rick rolled Link to comment https://forums.phpfreaks.com/topic/103186-solved-preg_replace-strip_tags/#findComment-528540 Share on other sites More sharing options...
eRott Posted April 27, 2008 Author Share Posted April 27, 2008 lol. While I did link to such a video (just for the example's sake), this is a real question, and I would appreciate a real answer . Link to comment https://forums.phpfreaks.com/topic/103186-solved-preg_replace-strip_tags/#findComment-528543 Share on other sites More sharing options...
Fadion Posted April 27, 2008 Share Posted April 27, 2008 Im not getting this right, u want to keep the video or remove it? For keeping it: <?php $message = "Hello dolly! [youtube]http://youtube.com/watch?v=eBGIQ7ZuuiU[/youtube]"; $pos1 = strpos($message, '[youtube]'); $pos2 = strpos($message, '[/youtube]', strlen('[/youtube]')); echo $text = substr($message, $pos1, $pos2); ?> For removing it: <?php $message = "Hello dolly! [youtube]http://youtube.com/watch?v=eBGIQ7ZuuiU[/youtube]"; $pos = strpos($message, '[youtube]'); echo $text = substr($message, 0, $pos); ?> Link to comment https://forums.phpfreaks.com/topic/103186-solved-preg_replace-strip_tags/#findComment-528548 Share on other sites More sharing options...
MadTechie Posted April 27, 2008 Share Posted April 27, 2008 try this <?php $message = "Hello dolly! [youtube]http://youtube.com/watch?v=eBGIQ7ZuuiU[/youtube]"; if (preg_match('%(\[youtube\].*?\[/youtube\])%simx', $message, $regs)) { $message = $regs[1]; } echo $message; //removed the Hello dolly! ?> OR <?php $message = "Hello dolly! [youtube]http://youtube.com/watch?v=eBGIQ7ZuuiU[/youtube]"; $message= preg_replace('%(\[youtube\].*?\[/youtube\])%sim', '', $message); echo $message; // show the Hello dolly! ?> Link to comment https://forums.phpfreaks.com/topic/103186-solved-preg_replace-strip_tags/#findComment-528569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.