We help IT Professionals succeed at work.

Php, Verify if a string contain "."

Pedro Chagas
Pedro Chagas asked
Hi E's, I need to verify if a $string contain ".".
if ($string contain .){
contain} else{ no contain}

How I do this?

The best regards, JC
Watch Question

Senior Performance Engineer
strpos() is the best for this:

$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";

Open in new window

Source: http://php.net/manual/en/function.strpos.php

Explore More ContentExplore courses, solutions, and other research materials related to this topic.