christa Posted April 11, 2011 Share Posted April 11, 2011 $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 Quote Link to comment https://forums.phpfreaks.com/topic/233388-to-obtain-image-info/ Share on other sites More sharing options...
requinix Posted April 11, 2011 Share Posted April 11, 2011 Use preg_replace_callback and a function to do the replacing for that one tag. Quote Link to comment https://forums.phpfreaks.com/topic/233388-to-obtain-image-info/#findComment-1200202 Share on other sites More sharing options...
christa Posted April 11, 2011 Author Share Posted April 11, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/233388-to-obtain-image-info/#findComment-1200216 Share on other sites More sharing options...
requinix Posted April 11, 2011 Share Posted April 11, 2011 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 ); Quote Link to comment https://forums.phpfreaks.com/topic/233388-to-obtain-image-info/#findComment-1200231 Share on other sites More sharing options...
christa Posted April 12, 2011 Author Share Posted April 12, 2011 i've tried your code but it just returns the path to image and not the width and height: matches[0]= , matches[1]=, matches[2]=http://localhost/app/images/stuff.gif Quote Link to comment https://forums.phpfreaks.com/topic/233388-to-obtain-image-info/#findComment-1200650 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.