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 :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
post_proc.inc.t [message #40495] Mon, 10 March 2008 21:16 Go to previous message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma:
Senior Member
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 21:17]

Report message to a moderator

[Message index]
 
Read Message
Read Message
Previous Topic: a forum is hiding..
Next Topic: Invisible forums?
Goto Forum:
  

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

Current Time: Wed Nov 13 06:45:07 GMT 2024

Total time taken to generate the page: 0.04775 seconds