Jump to content

PHP Equivalent of Perl's =~


yfjpe

Recommended Posts

Hi there, I am new to PHP and have what is probably a very basic question.

In Perl, when you want to find a certain string within a value, you can use the following:

if ($value =~ /$string/) { }

So, if $value is "Toob Goob Joob" and you want to find "Goob", the if statement above would be true.

All I need to know is how to do this in PHP. Thanks in advance for your help.
Link to comment
https://forums.phpfreaks.com/topic/27385-php-equivalent-of-perls-~/
Share on other sites

That type of matching (=~) is using regular expressions to run the match. This is the equivalent of using preg_match() in PHP. Here is a similar equivalent:
[code]
<?php
$string = "Toob Goob Joob";
if (preg_match('/Goob/', $string)) {
  // match found
}
?>
[/code]

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.