I need help to debug this script..
I can't tell whats wrong... might the patterns iam using for reg.exp..
The one thing I do know, is that it doesnt transform the "http"/"ftp" words to text/img link in my string.. anyone??
function Check_if_Image($matches) {
$suffix = strtolower(substr($matches[0],-4));
if ( $suffix == '.jpg' or $suffix == '.gif') {
$dsn = 'http'.$matches[3].'://'.$matches[4].$matches[5];
if (list($width, $height, $type, $attr) = getimagesize("$dsn")) {
if ( ($width > 600) ) {
$koef = $width / 600;
$width = 600;
$height /= $koef;
}
if ( ($height > 400) ) {
$koef = $height / 400;
$height = 400;
$width /= $koef;
}
}
else {
$height=400;
$width=600;
}
$ret = "<img src=\"$dsn\"";
$ret .= "\" border=0 width=\"$width\" height=\"$height\">";
}
else {
$ret = '<a href="http'.$matches[3].'://'.$matches[4].$matches[5];
$ret .='" target="_blank">'.$matches[0].'</a>';
}
return ("$ret");
}
$pattern_html = "/((http|ftp)+(s)?:\/\/[^<>\s]+)/i";
$text = preg_replace_callback($pattern_html,'Check_if_Image',$text);