Henaro Posted June 17, 2007 Share Posted June 17, 2007 Hey everyone. I'm having a bit of trouble with one of my scripts. The error I'm getting is this: Warning: preg_replace(): Unknown modifier 'w' in html/board/boards/post_topic.php on line 66 Here's line 66: $str = preg_replace ($simple_search, $simple_replace, $str); And here's the code I just added that I am suspicious about: '/\[yt\]http:\/\/youtube.com/watch?v=(.*?)\[\/yt\]/', Which goes to: '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>', The whole idea is to let users embed youtube videos. But it seems like it's not working correctly. Here's the whole function: function BBCode ($str) { $simple_search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url\](.*?)\[\/url\]/is', '/(>>)([0-9]+)/', '/\[img\](.*?)\[\/img\]/is', '/\[yt\]http:\/\/youtube.com/watch?v=(.*?)\[\/yt\]/', '/\[em\](.*?)\[\/em\]/is', '/\[txt\](.*?)\[\/txt\]/is' ); $simple_replace = array( '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', '<a href="$1">$2</a>', '<a href="$1">[link]</a>', '<a href=\'index.php#$2\'>$1$2</a>', '<a href="$1"><img src="$1" boarder=0 /></a>', '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>', '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="550" HEIGHT="400" id="Embeded File"><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src="$1" quality=high bgcolor=#FFFFFF WIDTH="550" HEIGHT="400" NAME="Embeded File" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>', '<div class="code">$1</div>' ); // Do simple BBCode's $str = preg_replace ($simple_search, $simple_replace, $str); return $str; } I can't really think of a solution for this. It's 1:30AM right now though, so it could be that I'm just tired and not seeing straight. But I hope someone can help me out. Thanks, Henaro Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/ Share on other sites More sharing options...
sasa Posted June 17, 2007 Share Posted June 17, 2007 youtube.com\/watch Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-276169 Share on other sites More sharing options...
Henaro Posted June 17, 2007 Author Share Posted June 17, 2007 Wow I missed that one! But now the [yt] tags won't work at all. Am I doing it wrong? ??? Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-276177 Share on other sites More sharing options...
sasa Posted June 17, 2007 Share Posted June 17, 2007 sorry '/\[yt\]http:\/\/youtube.com\/watch\?v=(.*?)\[\/yt\]/' escape '?' too Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-276351 Share on other sites More sharing options...
Henaro Posted June 21, 2007 Author Share Posted June 21, 2007 Hello again~ Sorry for resurrecting this posts, but I thought it would be better than creating a new one. I seem to have broken it. I moved the BBCode function onto a file called fun.php. Which is included correctly on the post_reply file. But now it seems like it broke the youtube tag (which was working fine with your help). All of the other BBcode works except for this. ??? Anyone know what might be wrong? '_' Thanks, Henaro EDIT: And here's the full code: <?php function BBCode ($str) { $simple_search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url\](.*?)\[\/url\]/is', '/(>>)([0-9]+)/', '/\[img\](.*?)\[\/img\]/is', '/\[yt\]http:\/\/youtube.com\/watch\?v=(.*?)\[\/yt\]/', '/\[em\](.*?)\[\/em\]/is', '/\[txt\](.*?)\[\/txt\]/is' ); $simple_replace = array( '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', '<a href="$1">$2</a>', '<a href="$1">[link]</a>', '<a href=\'index.php#$2\'>$1$2</a>', '<a href="$1"><img src="$1" boarder=0 /></a>', '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>', '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="550" HEIGHT="400" id="Embeded File"><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src="$1" quality=high bgcolor=#FFFFFF WIDTH="550" HEIGHT="400" NAME="Embeded File" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>', '<div class="code">$1</div>' ); // Do simple BBCode's $str = preg_replace ($simple_search, $simple_replace, $str); return $str; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-279163 Share on other sites More sharing options...
Wildbug Posted June 21, 2007 Share Posted June 21, 2007 '/\[yt\]http:\/\/(?:www\.)?youtube\.com\/watch\?v=(.*?)\[\/yt\]/i', ??? Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-279344 Share on other sites More sharing options...
Henaro Posted June 21, 2007 Author Share Posted June 21, 2007 I completely forgot about the www. part. Thatks a lot it works now. Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-279443 Share on other sites More sharing options...
phpsycho Posted July 2, 2011 Share Posted July 2, 2011 This is pretty old lol but... youtube embed is now running off a iframe.. say someone goes to a youtube video and there is more text after the "video id" like &feature= blah blah blah.. well they copy that and insert it into the forum post using a youtube bbc tag. the video won't work because it didn't remove the text after the video id. now I know I can use str replace and what not to remove specific text, but how would I remove anything after the youtube video id? Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1237769 Share on other sites More sharing options...
xyph Posted July 4, 2011 Share Posted July 4, 2011 You'd have to give us more absolute examples. What is the string you'd like? What kind of strings are you getting? Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1238294 Share on other sites More sharing options...
phpsycho Posted July 5, 2011 Share Posted July 5, 2011 Well say someone inputs this: I got it to remove the beginning (http://www.youtube.com/watch?v=) but what about the ending? (&feature=related) That needs to be removed, youtube's embedded code doesn't work with &feature &NR etc after its video id anymore. is there a way to remove the ending of the url so only the video id is left? I think every video id is 11 characters if that helps any. Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1238417 Share on other sites More sharing options...
xyph Posted July 5, 2011 Share Posted July 5, 2011 Of course. <?php $str = 'heres a query in the right order [youtube]http://www.youtube.com/watch?v=DUyn5qyf_6c&feature=related[/youtube] and heres one in the wrong order [youtube]http://www.youtube.com/watch?feature=related&v=DUyn5qyf_6c[/youtube] both should work fine.'; $expr = '%\[youtube\](?:http://){0,1}(?:www.){0,1}youtube.com/watch\?.*?v=([^&[]++)[^[]*+\[/youtube\]%i'; preg_match_all( $expr, $str, $matches, PREG_SET_ORDER ); print_r( $matches ); ?> HTH. Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1238620 Share on other sites More sharing options...
phpsycho Posted July 6, 2011 Share Posted July 6, 2011 I'm drawing a blank.. XD how would I make it so its not an array. Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239272 Share on other sites More sharing options...
xyph Posted July 6, 2011 Share Posted July 6, 2011 preg_match and preg_match_all both reference arrays of matches. You probably want to use preg_replace() anyways. Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239277 Share on other sites More sharing options...
phpsycho Posted July 6, 2011 Share Posted July 6, 2011 ah duh I was trying str_replace. hmm still confused though with preg_replace. What do I put in for pattern? EDIT: thanks! I got it now Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239283 Share on other sites More sharing options...
phpsycho Posted July 6, 2011 Share Posted July 6, 2011 So I removed the because I gotta have those removed for the other functions to work but.. its not working since I removed those. <?php $str = 'heres a query in the right order [youtube]http://www.youtube.com/watch?v=DUyn5qyf_6c&feature=related[/youtube] and heres one in the wrong order [youtube]http://www.youtube.com/watch?feature=related&v=DUyn5qyf_6c[/youtube] both should work fine.'; $expr = '%\(?:http://){0,1}(?:www.){0,1}youtube.com/watch\?.*?v=([^&[]++)[^[]*+\%i'; $replacement = '${1}1,$3'; $matches = preg_replace($expr, $replacement, $str); echo $matches; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239295 Share on other sites More sharing options...
xyph Posted July 6, 2011 Share Posted July 6, 2011 That's not the expression I provided for you :/ Also, check out the preg_replace syntax. http://php.net/preg_replace Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239298 Share on other sites More sharing options...
phpsycho Posted July 6, 2011 Share Posted July 6, 2011 Yeah I know.. I was saying I needed to remove the youtube bbc tags for my other functions to work and now that I did that it doesn't work. Yeah I was reading up on that, I'll continue to do so Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239314 Share on other sites More sharing options...
Maq Posted July 6, 2011 Share Posted July 6, 2011 Just an FYI, before you replied, the last post was from 2007. Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239324 Share on other sites More sharing options...
phpsycho Posted July 7, 2011 Share Posted July 7, 2011 Yeah I know... soo? Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239356 Share on other sites More sharing options...
Maq Posted July 7, 2011 Share Posted July 7, 2011 Yeah I know... soo? If you have a new question, then start your own thread, don't revive old ones. If you want to reference this one, then link it Quote Link to comment https://forums.phpfreaks.com/topic/55913-solved-preg_replace-help-possibly-regex/#findComment-1239709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.