I’m trying to find a string inside of another string (I tried using strpos, but did not get any results back) using PHP. Here’s what I’ve tried:
$assignedBuildings = " , building 1, building 2, building 3";
$buildingName = "building 1";
$assArray = array_map('trim', explode(',', $assignedBuildings));
print_r($assArray);
echo("Looking for: " . $buildingName . " in " . $assignedBuildings);
$pos = in_array($buildingName, $assArray);
the print_r gets me this:
Array
(
[0] =>
[1] => Test Chapter
[2] => Test 2 Chapter
[3] => Test 3 Chapter
)
and when I echo $pos, I get nothing (as in “”).
Let’s pretend $buildingName is “Test 3 Chapter”. How would I find it in $assArray?
If the list of assigned buildings is a comma separated list, I’d suggest exploding it, then checking for your value in the resultant array. So, something like this:
Things to note: