Forum Moderators: coopster
And yes one more thing...can I search the string with a start and ending tag? for example....suppose i want to search line which start with "al" and ends with "kum"
Thanks in advance
A regular expression is likely to be your best option. intval [php.net] is not going to work as you expect ...
$string = 'My string has 123 in the middle';
var_dump(intval($string)); // prints int(0)
exit;
$my_string = 'Here is my 12345 number...';
if (preg_match('/(\d+)/', $my_string, $matches)) {
echo "First number found: {$matches[1]}";
} else {
echo "No numbers found, sorry!";
}
To extract al...kum matching strings:
$my_string = 'lorem ipsm dolor sit amet altestkum';
if (preg_match('/(al.+kum)/', $my_string, $matches)) {
echo "Something found: {$matches[1]}";
} else {
echo "No matches found, sorry!";
}
echo '<pre>';
echo $my_string = 'Here is my -123.45 number, and a 35-number, finally a -0.5...';
if (preg_match_all('/(-?[0-9]+(\.?[0-9]+)?)/', $my_string, $matches)) {
echo PHP_EOL.'First number found: '.$matches[0][0].PHP_EOL;
print_r($matches[0]);
} else {
echo "No numbers found, sorry!";
}