php - How find words and abolish (delete) characters after it based in a list? -


if want check 'php' exist in string , delete words after use:

$string = 'hello world php bla bla..'; $string = explode(' php ', $string); echo $string[0]; 

but if have multiple words instead of 'php'? example few song name below has 'feats','feat','ft','ft.'.. that's 4 of them.

i want make 'sia - elastic feat brunos mars' become 'sia - elastic'.

this code need:

<?php  $string = 'sia - elastic feat brunos mars';  $array = array('feats', 'feat', 'ft', 'ft.');  for($i = 0; $i < count($array); $i++) {   $out = explode(' ' . $array[$i] . ' ', $string);   if (count($out) > 1) {        break;   }    }  echo $out[0];  ?> 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -