Strings and Text
String Search
strpos finds the first position where a substring appears.
String Search
string_search.php
<?php
$term = ;
$text = "cat dog fox";
$position = strpos($text, $term);
$found = $position !== false;
$label = $found ? "found" : "missing";
echo "term=" . $term . "\n";
echo "position=" . $position . "\n";
echo "label=" . $label . "\n";
<?php
$term = ;
$text = "cat dog fox";
$position = strpos($text, $term);
$found = $position !== false;
$label = $found ? "found" : "missing";
echo "term=" . $term . "\n";
echo "position=" . $position . "\n";
echo "label=" . $label . "\n";
<?php
$term = ;
$text = "cat dog fox";
$position = strpos($text, $term);
$found = $position !== false;
$label = $found ? "found" : "missing";
echo "term=" . $term . "\n";
echo "position=" . $position . "\n";
echo "label=" . $label . "\n";
search result
A search can return a numeric position; position zero is still a real match.