FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » Preg replace problem (again!)
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Preg replace problem (again!) [message #160140] Tue, 28 July 2009 21:37 Go to next message
nozafc is currently offline  nozafc   United Kingdom
Messages: 75
Registered: April 2009
Karma: 0
Member
As usual when I'm writing a plugin I have issues with converting HTML code back to BBcode when quoted/edited

Finally got the hang of regex Surprised just need to get the hang of this

Any idea what I require to change from the code below to get a proper HTML -> BBCode. Probably something obvious, it works fine as far as embedding the video just doesn't work when quoting/editing and you end up with HTML.

<?php
 // Initialize plugin
 plugin_add_hook("BBCODE2HTML", "plugin_zshare_tag_to_html");
 plugin_add_hook("HTML2BBCODE", "plugin_zshare_html_to_tag");
 
  // Convert [zshare] to html code (post message)
 function plugin_zshare_tag_to_html($array) {
 	list($bbcode) = $array;
 
 	$bbcode = preg_replace('#\[zshare\]([a-zA-Z0-9%_=.&(?!amp;)-]+)\[/zshare\]#si', '<iframe src="http://www.zshare.net/videoplayer/player.php?\\1&iframewidth=530&iframeheight=435&width=480&height=385&H=1&ISL=1" height="435" width="530" border=0 frameborder=0 scrolling=no id="videoframe" name="videoframe"></iframe>', $bbcode);
 	return array($bbcode);
 }

 // Convert html to [zshare] tag (edit message)
 function plugin_zshare_html_to_tag($array) {
 	list($bbcode) = $array;
 
 	$bbcode = preg_replace('#<iframe src="<iframe src="http://www.zshare.net/videoplayer/player.php?([a-zA-Z0-9%_=.&(?!amp;)-]+)&iframewidth=530&iframeheight=435&width=480&height=385&H=1&ISL=1" height="435" width="530" border=0 frameborder=0 scrolling=no id="videoframe" name="videoframe"></iframe>#si', '[zshare]\\1[/zshare]', $bbcode);
 	return array($bbcode);
 }
Re: Preg replace problem (again!) [message #160142 is a reply to message #160140] Wed, 29 July 2009 01:55 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3772
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Remove the extra <iframe src=" from the last regex.
Re: Preg replace problem (again!) [message #160144 is a reply to message #160140] Wed, 29 July 2009 12:01 Go to previous message
nozafc is currently offline  nozafc   United States
Messages: 75
Registered: April 2009
Karma: 0
Member
Laughing Laughing Laughing

I can't test it right now as I'm at work but I can't believe I missed that Laughing Embarassed
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: java script to php
Next Topic: Launching a php script file
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 22 04:00:14 GMT 2024

Total time taken to generate the page: 0.04854 seconds