substring

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Swathimaddipatla
Forum Newbie
Posts: 9
Joined: Fri May 09, 2008 7:08 am

substring

Post 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;
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: substring

Post by VladSun »

You need a regexp:

Code: Select all

 
preg_match('/onClick="PostPageT\(\s*\'(.*)\'\s*,\s*\'false\'\s*\);"/', $string, $matches);
print_r($matches);
 
There are 10 types of people in this world, those who understand binary and those who don't
Swathimaddipatla
Forum Newbie
Posts: 9
Joined: Fri May 09, 2008 7:08 am

Re: substring

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: substring

Post 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);
 
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply