phpを使用して、正確な文字列に一致する正規表現は何ですか。
テキストがあるとしましょう:
Hello, world.
How are you today?
Today is sunshine and snow wouldn't you know.
文字列を照合するために正規表現をどのように使用しますか?:
sunshine and snow
phpを使用して、正確な文字列に一致する正規表現は何ですか。
テキストがあるとしましょう:
Hello, world.
How are you today?
Today is sunshine and snow wouldn't you know.
文字列を照合するために正規表現をどのように使用しますか?:
sunshine and snow
preg_matchの使用:
<?php
// The "i" after the pattern delimiter indicates a case-insensitive search
if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
?>
strposの使用:
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>