Page 1 of 1
how to fetch string using php function
Posted: Tue Jan 31, 2006 4:44 am
by itsmani1
i want to select ABC and DEF using some php method/funciton? is there any?
Code: Select all
<OPTION>ABC</OPTION>
<OPTION>DEF</OPTION>
Posted: Tue Jan 31, 2006 4:55 am
by JayBird
something like
Code: Select all
<?
// the string
$string = "<OPTION>ABC</OPTION>";
// store matches in array
$match = array();
// search for a match
preg_match('~<OPTION>(.*?)</OPTION>~si', $string, $match);
echo $match[0];
// outputs: ABC
?>
Posted: Tue Jan 31, 2006 5:03 am
by itsmani1
Code: Select all
$string = "<OPTION>ABC</OPTION><OPTION>DEF</OPTION>";
// store matches in array
$match = array();
// search for a match
preg_match('~<OPTION>(.*?)</OPTION>~si', $string, $match);
echo $match[0];
echo $match[1];
but in this case it don't gave me
ABC
DEF
Posted: Tue Jan 31, 2006 5:14 am
by JayBird
Use preg_match_all instead
Code: Select all
<?
// the string
$string = "<OPTION>ABC</OPTION><OPTION>DEF</OPTION>";
// store matches in array
$match = array();
// search for a match
preg_match_all('~<OPTION>(.*?)</OPTION>~', $string, $match);
//echo $match[0];
echo "<pre>";
print_r($match);
echo "</pre>";
?>