ok that avoid transforming the ones that not has a blank space in front.. but now it doesnt transform the others, that are "ok"..
The might some other thinks in the script that fucks up..
doesnt seems that the "if()" runs in the CheckImage function...
function transform($text){
$pattern_html = "#\b(http|https|ftp|ftps)://([^<>\s]+)#i";
$text = preg_replace_callback($pattern_html,'Check_if_Image',$text);
return $text;
}
function Check_if_Image($matches) {
//print "<pre>"; var_dump($matches); print "</pre><hr>\n";
$dst = $matches[0];
if(@fopen($dst, 'r')){
$suffix = strtolower(substr($matches[0],-4)); // last 4 chars of match
if ( $suffix == '.jpg' or $suffix == '.gif') {
$dsn = $matches[0]; // $matches[1].'://'.$matches[2];
if (list($width, $height, $type, $attr) = getimagesize($dsn)) {
if ( ($width > 150) ) {
$koef = $width / 150;
$width = 150;
$height /= $koef;
}
if ( ($height > 150) ) {
$koef = $height / 150;
$height = 150;
$width /= $koef;
}
}
else {
$height=150;
$width=150;
}
$ret = "<img src=\"$dsn\"";
$ret .= "\" border=0 width=\"$width\" height=\"$height\" style=\"display:block;\">";
} else {
$ret = '<a href="'.$matches[0].'" target="_blank">'.$matches[0].'</a>';
}
return $ret;
}
else {
return '';
}
}