Page 1 of 1

substring

Posted: Fri May 16, 2008 1:58 am
by Swathimaddipatla
hi folks...

Variable contains a string which includes html tags...etc...
i need to get booayt28.05.2008uze2u from the variable string...

am trying like this...but its not showing any o/p

$string = "<tr><td bgcolor='#E5ECF9' valign='top'>28.05.2008<BR>Bodø</td><td bgcolor='#E5ECF9' valign='top'><a href='#' onClick='OpenHotel(32);'>Uzel Hotel 2 uker med frokost </a></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>NOK 3 890</div></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>7<td bgcolor='#E5ECF9' valign='top' nowrap><div align='right'><a href='#' onClick="PostPageT('booayt28.05.2008uze2u','false' );"><b><font color=#ff9900>Bestill nå</font></b> »</a>";

$pos13 = strpos($row,"<a href='#' onClick=".'"'."PostPageT('");
//echo $pos13;
$buff = substr($row,$pos13+11);
$pos14 = strpos($buff,"',','false');".'"'."><b>");
$Value = substr($row,$pos13+11,$pos14);
echo "Value : ".$Value;

Re: substring

Posted: Fri May 16, 2008 2:25 am
by VladSun
You need a regexp:

Code: Select all

 
preg_match('/onClick="PostPageT\(\s*\'(.*)\'\s*,\s*\'false\'\s*\);"/', $string, $matches);
print_r($matches);
 

Re: substring

Posted: Fri May 16, 2008 2:33 am
by Swathimaddipatla
actually problem occurs in the string assigned to variable...
string assigned to the variable consists double quote("PostPageT('booayt28.05.2008uze2u','false'); ") inside a sting.....in normal cases i can make it as single quote..but the thing is i cant modify the string.am getting this string as response from some other....

with out changing string in a variable..i need to out put booayt28.05.2008uze2u...

i think u have understood my problem....
pls..help me

Re: substring

Posted: Fri May 16, 2008 2:38 am
by VladSun

Code: Select all

 
$string = "<tr><td bgcolor='#E5ECF9' valign='top'>28.05.2008<BR>Bodø</td><td bgcolor='#E5ECF9' valign='top'><a href='#' onClick='OpenHotel(32);'>Uzel Hotel 2 uker med frokost </a></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>NOK 3 890</div></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>7<td bgcolor='#E5ECF9' valign='top' nowrap><div align='right'><a href='#'  onClick=\"PostPageT('booayt28.05.2008uze2u','false');\"><b><font color=#ff9900>Bestill nå</font></b> »</a>";
 
preg_match('/onClick=[\'"]PostPageT\(\s*[\'"](.*)[\'"]\s*,\s*[\'"]false[\'"]\s*\);[\'"]/', $string, $matches);
print_r($matches);