Jump to content

To obtain image info


christa

Recommended Posts

$search = array(

'{\[quote\](\r\n|\r|\n)*(.+)\[/quote\]}siU',
'{\[img\](\r\n|\r|\n)*((http)://([^;<>\*\(\)"\s]+)|[\w/\\\._\- ]+)\[/img\]}siU'
);
$replace = array(
'<b>\\2</b>',
'<img src="\\2"  alt="img" />'
);
$mytext = preg_replace($search, $replace, $mytext);

 

I need to obtain the size and dimensions of image found in replace array using getimagesize(): how can I do?

The image in the code above is \\2

regards :)

 

 

Link to comment
https://forums.phpfreaks.com/topic/233388-to-obtain-image-info/
Share on other sites

i've edited as:

 

function imgsize($myimg){
return getimagesize($myimg);
}

$search = array(
'{\[quote\](\r\n|\r|\n)*(.+)\[/quote\]}siU',
'{\[img\](\r\n|\r|\n)*((http)://([^;<>\*\(\)"\s]+)|[\w/\\\._\- ]+)\[/img\]}siU'
);
$replace = array(
'<b>\\2</b>',
'' . imgsize(\\2) . '<img src="\\2"  alt="img" />'
);
$mytext = preg_replace_callback($search, $replace, $mytext);

 

Now i obtain this result:

 

Warning: getimagesize(\2): failed to open stream: No such file or directory...

Warning: preg_replace_callback(): Requires argument 2, 'Array', to be a valid callback in...

Try reading a little more carefully. And try using php tags:

function replaceimg($matches) {
    return "matches[0]=" . $matches[0] . ", matches[1]=" . $matches[1] . ", matches[2]=" . $matches[2];
}

// simple
$search = array(
'{\[quote\](\r\n|\r|\n)*(.+)\[/quote\]}siU'
);
$replace = array(
'\\2'
);
$mytext = preg_replace($search, $replace, $mytext);

// complex
$mytext = preg_replace_callback(
    '{\[img\](\r\n|\r|\n)*((http)://([^;\*\(\)"\s]+)|[\w/\\\._\- ]+)\[/img\]}siU',
    "replaceimg",
    $mytext
);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.