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

Home » FUDforum » How To » post_proc.inc.t (preg_replace and strpos question)
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
post_proc.inc.t [message #40495] Mon, 10 March 2008 17:16 Go to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
So I added an image resize script, which gives an image with larger than X pixels width a reduced size.

The resize part works fine and the images render perfectly and my click to resize script works fine as well.

My problem occurs when I want to edit a post where I have previously posted an image where the resize was tirggered.

This is the old original Ilya code for reference:
	while (preg_match('!<img src="(.*?)" border=0 alt="\\1">!is', $fudml)) {
		$fudml = preg_replace('!<img src="(.*?)" border=0 alt="\\1">!is', '[img]\1[/img]', $fudml);
	}
	while (preg_match('!<img class="(r|l)" src="(.*?)" border=0 alt="\\2">!is', $fudml)) {
		$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" border=0 alt="\\2">!is', '[img\1]\2[/img\1]', $fudml);
	}
	while (preg_match('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', $fudml)) {
		$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', '[email]\1[/email]', $fudml);
	}
	while (preg_match('!<a href="(.+?)" target="_blank">\\1</a>!is', $fudml)) {
		$fudml = preg_replace('!<a href="(.+?)" target="_blank">\\1</a>!is', '[url]\1[/url]', $fudml);
	}

	if (strpos($fudml, '<img src="') !== false) {
		$fudml = preg_replace('!<img src="(.*?)" border=0 alt="(.*?)">!is', '[img=\1]\2[/img]', $fudml);
	}
	if (strpos($fudml, '<img class="') !== false) {
		$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" border=0 alt="(.*?)">!is', '[img\1=\2]\3[/img\1]', $fudml);
	}
	if (strpos($fudml, '<a href="mailto:') !== false) {
		$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">(.+?)</a>!is', '[email=\1]\2[/email]', $fudml);
	}
	if (strpos($fudml, '<a href="') !== false) {
		$fudml = preg_replace('!<a href="(.+?)" target="_blank">(.+?)</a>!is', '[url=\1]\2[/url]', $fudml);
	}

	if (isset($php)) {
		$fudml = str_replace(array_keys($php), array_values($php), $fudml);
	}




This is my altered, not working code. I must have done something wrong, if anyone could point out where my error is, I will kiss you on the mouth and make babies with you!

while (preg_match('!<a onclick="return hs.expand(this, {allowSizeReduction: false})" href="(.*?)" class="highslide" target="_new"><img border="0" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" alt="(.*?)"></a>!is', $fudml)) {
		$fudml = preg_replace('!<a onclick="return hs.expand(this, {allowSizeReduction: false})" href="(.*?)" class="highslide" target="_new"><img border="0" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" alt="(.*?)"></a>!is', '[img]\5[/img]', $fudml);
	}
	while (preg_match('!<img src="(.*?)" style="width:(.*?)px; height:(.*?)px" border="0" alt="\\4">!is', $fudml)) {
		$fudml = preg_replace('!<img src="(.*?)" style="width:(.*?)px; height:(.*?)px;" border="0" alt="\\4">!is', '[img]\4[/img]', $fudml);
	}
	while (preg_match('!<img class="(r|l)" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" border="0" alt="\\5">!is', $fudml)) {
		$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" border="0" alt="\\5">!is', '[img\1]\5[/img\1]', $fudml);
	}
	while (preg_match('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', $fudml)) {
		$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', '[email]\1[/email]', $fudml);
	}
	while (preg_match('!<a href="(.+?)" target="_blank">\\1</a>!is', $fudml)) {
		$fudml = preg_replace('!<a href="(.+?)" target="_blank">\\1</a>!is', '[url]\1[/url]', $fudml);
	}

	if (strpos($fudml, '<img src="') !== false) {
		$fudml = preg_replace('!<img src="(.*?)" style="width:(.*?)px; height:(.*?)px;" border="0" alt="(.*?)">!is', '[img]\4[/img]', $fudml);
	}
	if (strpos($fudml, '<img class="') !== false) {
		$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" style="width:(.*?)px height:(.*?)px;" border="0" alt="(.*?)">!is', '[img\1=\2]\5[/img\1]', $fudml);
	}
	if (strpos($fudml, '<a onclick') !== false) {
		$fudml = preg_replace('!<a onclick="return hs.expand(this, {allowSizeReduction: false})" href="(.*?)" class="highslide" target="_new"><img border="0" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" alt="(.*?)"></a>!is', '[img]\1[/img]', $fudml);
	}
	if (strpos($fudml, '<a href="mailto:') !== false) {
		$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">(.+?)</a>!is', '[email=\1]\2[/email]', $fudml);
	}
	if (strpos($fudml, '<a href="') !== false) {
		$fudml = preg_replace('!<a href="(.+?)" target="_blank">(.+?)</a>!is', '[url=\1]\2[/url]', $fudml);
	}

	if (isset($php)) {
		$fudml = str_replace(array_keys($php), array_values($php), $fudml);
	}



Just as a reference, this is the code that the script creates:
<a onclick="return hs.expand(this, {allowSizeReduction: false})" href="'.$parms.'" class="highslide" target="_new"><img border="0" src="'.$parms.'" style="width:'.$imgw.'px; height:'.$imgh.'px;" alt="Click to view full-size"></a>


[Updated on: Mon, 10 March 2008 17:17]

Report message to a moderator

Re: post_proc.inc.t [message #40498 is a reply to message #40495] Mon, 10 March 2008 19:27 Go to previous message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
add to buddy list
ignore all messages by this user
I think your \\5 should be \\4, since there are only 4 capture blocks.

FUDforum Core Developer
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: a forum is hiding..
Next Topic: Invisible forums?
Goto Forum:
  

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

Current Time: Mon Oct 23 16:38:11 EDT 2017

Total time taken to generate the page: 0.00612 seconds