PHP / regex expert opinion needed

Community Forums/General Help/PHP / regex expert opinion needed

skidracer(Posted 2016) [#1]
I would like to add a short cut so anyone that uploads to gallery can then use
coming soon
to place clickable full version of said gallery image into a post.

But first, I was hoping to maybe "harden" up the youtube and new monkey tag handling first (which may or may not be postable in machine readable format on this host):

     //	<youtube youtube_id>
	$text=preg_replace(
	";\[youtube(\s+)(.+?)\];is",
        "<iframe width=\"560\" height=\"345\" src=\"http://www.youtube.com/embed/$2\" frameborder=\"0\" allowfullscreen></iframe>"
        ,$text );
    //	<gallery id>
	$text=preg_replace(
	";\[gallery(\s+)(.+?)\];is",
        "<div>coming soon</div>"
        ,$text );
    //	<monkey iframe>
	$text=preg_replace(
	";\[monkey(\s+)(.+?)\];is",
		'<iframe src="http://apps.monkey-x.com/$2/1/html5/MonkeyGame.php?width=640&amp;height=480" width="640" height="480" style="display:block;"></iframe>'
        ,$text );



Derron(Posted 2016) [#2]
So you just append whatever is given as "second param:

{monkey ../bad/worse/worst}

Eg. use this: https://regex101.com/
to check your regex online.


So for the monkey part:
";\[monkey(\s+)(\d+)\];is",


might do.

Regardless of that: I am not sure if it is a good idea to just "preg_replace" instead of replacing valid ones and erroring "post submission" on invalid ones.


Here is for youtube:
Format:
{youtube}https://www.youtube.com/watch?v=30Nm9mUKt2g{/video}
\{youtube\]([^\[<]*?)/(v/|watch\?v=)([^\[<]*?)\[/youtube\}


{youtube 30Nm9mUKt2g}description{/youtube}
\{youtube ([a-zA-Z0-9_]*)\](.*?)\[\/youtube\}

curly brackets by me to avoid auto-video-insertation which happens - EVEN IN THIS CODEBOX!!)




This is my suggestion, let's see what others say.


Edit: PHP offers preg_replace_callback() to handle things individually.


More important: video links in code-tags are converted to videos instead of being kept as raw links.
Therefor on processing a post you need to split "content" from "code in {code}-tags" (code needs to stay untouched).


Next to the things you are doing here: thought of replacing the forum with a lightweight solution (I am using fluxbb.com) which does that for you already? I know the forum was used in the past to bring together account credentials (registered products etc) and users. But with the things being free... just a thought.
And if not: their "includes/parser.php" should help you regarding some bbcode and code-block extraction.


bye
Ron


skidracer(Posted 2016) [#3]
Thanks Ron, those modifications are exactly what I had in mind.

The codebox thing would be nice to solve but we may need to take such discussion private. I am keen to make only small incremental changed to the site and have no interest in adapting any more third party craft.


skidracer(Posted 2016) [#4]
Ron, are you on LinkedIn?


Derron(Posted 2016) [#5]
Nope, but emailed you some minutes ago.


bye
Ron


GW(Posted 2016) [#6]
Also:
http://regexr.com/
http://www.regextester.com/