Question

I have a problem with preg_match

$versionstring[1] = 'Version: ImageMagick 6.4.6 2010-01-20 Q8 OpenMP http://www.imagemagick.org Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC';

preg_match('#^Version: [^0-9]*([ 0-9\\.\\:Q/\\-]+) (http|file)\:#i', $versionstring[1], $matches)) 

returns false

how can i fix this ?

Was it helpful?

Solution

OpenMP was added to the ImageMagic version string since your regex was working, so as a quick fix, you can just add OpenMP like this:

preg_match('#^Version: [^0-9]*([ 0-9\\.\\:Q/\\-]+) OpenMP (http|file)\:#i', $versionstring[1], $matches);

But just be aware that this could happen again on future upgrades, so depending on what you're using this for, you think about making the regex less string specific and just pull out the information you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top