Lemontree Posted August 21, 2011 Share Posted August 21, 2011 Hi! Can anyone please help me form script for doing a MySQL query based on variables in a bbcode? BBCode could be like this: [datatype::dataid] Explode datatype and dataid intro separate strings and using them in querys. Example of string containing bbcodes: $body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla, enim eget dictum sodales, enim velit iaculis dolor, sed congue orci diam id ipsum. Integer ullamcorper elit ac arcu condimentum id elementum arcu tempus. Ut aliquam commodo eros, mollis tristique magna adipiscing eu. [video::3456] Duis congue turpis quis eros porta eu sollicitudin mi porttitor. Ut ac nisi id risus imperdiet aliquet. Suspendisse lacinia sem id ipsum blandit egestas. Mauris id vulputate ligula. In in quam urna. Nam purus augue, laoreet vel sodales nec, rutrum non augue. [video::6789] Phasellus facilisis commodo arcu, vel dapibus tortor pretium eu. Integer elit nisi, condimentum ut vehicula eget, ullamcorper non quam. Nullam suscipit tempor consequat. Vestibulum sollicitudin ante tristique neque vestibulum a fermentum nulla venenatis. In eget nulla nulla."; I found something close here: http://stackoverflow.com/questions/2801228/php-bbcode-with-sql-selection Quote Link to comment https://forums.phpfreaks.com/topic/245337-mysql-query-based-on-bbcode/ Share on other sites More sharing options...
Lemontree Posted August 21, 2011 Author Share Posted August 21, 2011 Hi again. I found an answer to it myself. Worked a little with the code in the example on the link in previous post. I post the script here, in case someone need it: $body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla, enim eget dictum sodales, enim velit iaculis dolor, sed congue orci diam id ipsum. Integer ullamcorper elit ac arcu condimentum id elementum arcu tempus. Ut aliquam commodo eros, mollis tristique magna adipiscing eu.<br /><br />[video:1]<br /><br />Duis congue turpis quis eros porta eu sollicitudin mi porttitor. Ut ac nisi id risus imperdiet aliquet. Suspendisse lacinia sem id ipsum blandit egestas. Mauris id vulputate ligula. In in quam urna. Nam purus augue, laoreet vel sodales nec, rutrum non augue.<br /><br />[video:2]<br /><br />Phasellus facilisis commodo arcu, vel dapibus tortor pretium eu. Integer elit nisi, condimentum ut vehicula eget, ullamcorper non quam. Nullam suscipit tempor consequat. Vestibulum sollicitudin ante tristique neque vestibulum a fermentum nulla venenatis. In eget nulla nulla."; preg_match_all ( '#\[video:(.*?)\]#i', $body, $matches, PREG_SET_ORDER ); for ( $i = 0, $j = count( $matches ); $i < $j; $i++ ) { echo $matches[$i][0].", with ID: "; echo $matches[$i][1]."<br />"; $result = mysql_query("SELECT * FROM video WHERE id='".$matches[$i][1]."' AND validated='1' LIMIT 1"); while($row = mysql_fetch_array($result)) { $vid = $row['id']; $videoid = $row['videoid']; $videotype = $row['videotype']; } switch ($videotype): case 1: $body = str_replace($matches[$i][0], '<iframe width="650" height="366" src="http://www.youtube.com/embed/'.$videoid.'?autohide=1&border=0&modestbranding=1&showinfo=1&iv_load_policy=3&rel=0" frameborder="0" allowfullscreen></iframe>', $body); break; case 2: $body = str_replace($matches[$i][0], '<iframe src="http://player.vimeo.com/video/'.$videoid.'?byline=0&portrait=0&color=910007" width="650" height="366" frameborder="0"></iframe>', $body); break; default: echo ""; endswitch; } echo "<br />".$body; If it can be optimized, please do so... Quote Link to comment https://forums.phpfreaks.com/topic/245337-mysql-query-based-on-bbcode/#findComment-1260129 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.