Jump to content

[SOLVED] preg_replace // strip_tags


eRott

Recommended Posts

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

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);
?>

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! 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.