How can I change the strpos to make it non case sensitive. The reason is if the product->name
is MadBike and the search term is bike it will not echo me the link.
My main concern is the speed of the code.
<?php
$xml = simplexml_load_file('test.xml');
$searchterm = "bike";
foreach ($xml->product as $product) {
if (strpos($product->name, $searchterm) !== false ) {
echo $product->link;
} }
?>
strtolower()
first; on average, it (stripos
) seems to take about 2.5 times longer (thanstrpos
). Then again, you can still do it (stripos
) a million times per second, so I wouldn't worry that much about it -- premature optimization is the root of all evil. – Metrify