pattern matching - PHP - How to find a specific number in a string? -
i run sneakers affiliate site , trying match imported product names existing sneaker models keyword. many formats around have use number sometimes, , numbers don't matched code use. tried different php str- functions none of them seem both numbers , strings.
$models = array( '106' => 'vans 106 vulcanized', 'alomar' => 'vans alomar', 'atwood' => 'vans atwood', 'authentic' => 'vans authentic', // list goes on... ); foreach ( $models $model_keyword => $model_name ) { if ( stristr( $product_name, $model_keyword ) !== false ) { return $model_name; } }
as can see checking product name each of keywords , when it's found return model name. works every string contains letters or letters , numbers not numbers first item in array.
any ideas on how properly?
use strpos
instead.
<?php $models = array( '106' => 'vans 106 vulcanized', 'alomar' => 'vans alomar', 'atwood' => 'vans atwood', 'authentic' => 'vans authentic' // list goes on... ); foreach ($models $key => $name) { if (strpos($name, (string)$key) !== false) return $name; }
Comments
Post a Comment