-1

I'm writing a PhP script, but for a filter I need to search for a string in a string.
this is the script I have at the moment:

<?php
$stringtocheck = "Schiphol-Almere C./Hilversum/Utrecht C.";
$searchfor = "Hilversum";

// do the magic stuff over here
?>

How do i get the script to search for '$searchfor' in '$stringtocheck'?

Finlay Roelofs
  • 533
  • 6
  • 21

1 Answers1

2

Use strpos for to find the needle-string in the haystack-string. And here the haystack-string is stringtocheck and the needle-string is searchfor.

Example of using the function:

<?php
$stringtocheck = "Schiphol-Almere C./Hilversum/Utrecht C.";
$searchfor = "Hilversum";

if(strpos($stringtocheck, $searchfor) !== false)
    echo true;
?>
tripulse
  • 1,059
  • 11
  • 18
PRANAV
  • 629
  • 4
  • 13