PHP – Parse String with strpos()

The strpos() function allows you to parse strings in PHP.

strpos()

strpos.php

<?php

$string = "Hello bill bob";
$testWord = "bob";
$position = strpos($string, $testWord);
echo $testWord." is at: ".$position;

echo "<br><br>";

$array = array("jim bob", "tim tom", "frank furter");
foreach($array as $name) {
    if(strpos($name, "tom") == TRUE){
    echo $name."<br>";
}
}
echo "<br>";

exec("ip address",$exec);
$searchTerm = "inet ";
foreach($exec as $line){
    if(strpos($line,$searchTerm) == TRUE){
    echo $line."<br>";
   }
}   
?>

Be the first to comment

Leave a Reply