[PHP] preg_match_all question

2009-01-16 Thread Phil Ewington - iModel Ltd.

Hi All,

Having an issue with regular expressions, never been my strong point!

The following pattern only picks up one instance per line, if more than 
one instance exists all text from first {{ to last }} is included, can 
anyone point out where I am going wrong?


preg_match_all(/\{\{lang:(.*)\}\}/, $str, $tags);

Here is an example of what needs to be processed

ullispan{{lang:PA1Feature1}}/span/lilispan{{lang:PA1Feature2}}/span/li/ul
ullispan{{lang:PA2Feature1}}/span/lilispan{{lang:PA2Feature2}}/span/li/ul

TIA

Phil.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match_all question

2009-01-16 Thread Phil Ewington - iModel Ltd.

Robert Cummings wrote:

On Fri, 2009-01-16 at 09:42 +, Phil Ewington - iModel Ltd. wrote:
  

Hi All,

Having an issue with regular expressions, never been my strong point!

The following pattern only picks up one instance per line, if more than 
one instance exists all text from first {{ to last }} is included, can 
anyone point out where I am going wrong?


preg_match_all(/\{\{lang:(.*)\}\}/, $str, $tags);



You need the ungreedy modifier:

preg_match_all(/\{\{lang:(.*)\}\}/U, $str, $tags);

Cheers,
Rob.
  

Rob you're a star, thanks mate.

- Phil

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PECL JSON package

2008-12-11 Thread Phil Ewington - iModel

Hi All,

I have just installed the PECL JSON package, or at least think I have!! 
But how do I use it?? I was expecting /usr/share/pear/Services/JSON.php 
to be found on my system for include but not so. My system tells me I 
have 1.2.1 successfully installed but I cannot find any docs that tell 
me how to make use of it. I am running PHP 5.1.6 at present.


TIA

Phil.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PECL JSON package

2008-12-11 Thread Phil Ewington - iModel

Phil Ewington - iModel wrote:

Hi All,

I have just installed the PECL JSON package, or at least think I 
have!! But how do I use it?? I was expecting 
/usr/share/pear/Services/JSON.php to be found on my system for include 
but not so. My system tells me I have 1.2.1 successfully installed but 
I cannot find any docs that tell me how to make use of it. I am 
running PHP 5.1.6 at present.


TIA

Phil.

OK, seems I am confusing PECL and PEAR. Have now configured extension 
using phpize and enabled in php.ini.


- Phil.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PECL JSON package

2008-12-11 Thread Phil Ewington - iModel

Eric Butera wrote:

On Thu, Dec 11, 2008 at 5:43 AM, Phil Ewington - iModel
phil.ewing...@i-model.co.uk wrote:
  

Phil Ewington - iModel wrote:


Hi All,

I have just installed the PECL JSON package, or at least think I have!!
But how do I use it?? I was expecting /usr/share/pear/Services/JSON.php to
be found on my system for include but not so. My system tells me I have
1.2.1 successfully installed but I cannot find any docs that tell me how to
make use of it. I am running PHP 5.1.6 at present.

TIA

Phil.

  

OK, seems I am confusing PECL and PEAR. Have now configured extension using
phpize and enabled in php.ini.

- Phil.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





If you're using the pecl version, it is json_encode().

If you're using the pear version you say
require_once 'Services/JSON.php';
$json = new Services_JSON();
$output = $json-encode($value);

If you're using php5, you should have json in the build unless it was
disabled for some reason.  If you're going to be using it a lot,
you're really going to want the speed of the c version.

  
Yeah thanks. I am using the PECL version and have it compiled as an 
extension now working fine, just got confused with installing PEAR 
scripts. I have PHP 5.1.6, JSON only available in build from 5.2.0 I 
believe.


- Phil.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php