PHP equivalent to Perl"s !~

PHP equivalent to Perl"s !~

am 18.01.2008 21:07:49 von wes.waters

I haven't seen any documentation on this, and searching for !~ has
been fruitless. Any suggestions, or is there no equivalent?

Re: PHP equivalent to Perl"s !~

am 18.01.2008 22:06:10 von Michael Fesser

..oO(wes.waters@gmail.com)

>I haven't seen any documentation on this, and searching for !~ has
>been fruitless. Any suggestions, or is there no equivalent?

What about !preg_match()?

Just a guess, since I don't use Perl.

Micha

Re: PHP equivalent to Perl"s !~

am 19.01.2008 11:50:16 von Toby A Inkster

Michael Fesser wrote:
> .oO(wes.waters@gmail.com)
>
>>I haven't seen any documentation on this, and searching for !~ has been
>>fruitless. Any suggestions, or is there no equivalent?
>
> What about !preg_match()?
> Just a guess, since I don't use Perl.

Yep, that's correct.

Perl:

if ($foo !~ /bar/)
{
print "match\n";
}

PHP:

if (!preg_match('/bar/', $foo))
{
print "match\n";
}


--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 19 days, 22:02.]

Ham vs Bacon vs Pork
http://tobyinkster.co.uk/blog/2008/01/17/pork-etc/

Re: PHP equivalent to Perl"s !~

am 19.01.2008 17:08:29 von Courtney

Toby A Inkster wrote:
> Michael Fesser wrote:
>> .oO(wes.waters@gmail.com)
>>
>>> I haven't seen any documentation on this, and searching for !~ has been
>>> fruitless. Any suggestions, or is there no equivalent?
>> What about !preg_match()?
>> Just a guess, since I don't use Perl.
>
> Yep, that's correct.
>
> Perl:
>
> if ($foo !~ /bar/)
> {
> print "match\n";
> }
>
> PHP:
>
> if (!preg_match('/bar/', $foo))
> {
> print "match\n";
> }
>
>
And apart from reminding me of 'pregnancy' how much more readable the
PHP is!

Re: PHP equivalent to Perl"s !~

am 20.01.2008 00:44:06 von Toby A Inkster

The Natural Philosopher wrote:

> And apart from reminding me of 'pregnancy' how much more readable the
> PHP is!

Frankly I find the Perl version far more elegant. The lack of redundant
quote marks and nested brackets if far more pleasing to the eye IMHO.

Indeed, in Perl you could use:

print "match\n" if $foo !~ /bar/;

or even:

print "match\n" unless $foo =~ /bar/;

Either seem pretty readable to me.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 20 days, 10:51.]

Ham vs Bacon vs Pork
http://tobyinkster.co.uk/blog/2008/01/17/pork-etc/