i have a string:
$string = "test1 - test2 - kw: test - key: 123 - test5";
and im trying to get this result:
kw = test;
key = 123;
I’ve tried spiting the string:
$array = explode("-", $str );
print_r($array);
and the result is:
Array
(
[0] => test1
[1] => test2
[2] => kw: test
[3] => key: 123
[4] => test5
)
from here i would like to do something like:
$str = 'kw:';
if ( in_array ( $str , $array ) ) {
echo 'It exists';
} else {
echo 'Does not exist';
}
or
$kw = array_search('kw:', $array );
but $array is an arrays of array.
im not sure how to proceed from here.
any ideas? Is there another way of extracting those words?
thanks
Using preg_match this becomes really easy:
Should return an array of matches that correspond to what you are looking for…
For more information regarding regular expressions (Very powerful tool):
http://www.regular-expressions.info/tutorial.html