Jump to content

replace part of a <ahref


poe

Recommended Posts

i grabbed a table and loop through each <tr> into an array

 

i am now cleaning the tags like so:

 

foreach($strHtml as $k => $v)
{
$myHtml = $v;
$myHtml = preg_replace('/\s+/s',"",$myHtml);
$myHtml = preg_replace('/^\s+/s',"",$myHtml);
$myHtml = preg_replace('/\s+$/s',"",$myHtml);
$myHtml = preg_replace('#(?<=>)([a-zA-Z0-9]+)/(?=[a-zA-Z0-9]+<)#', '\1:', $myHtml);
$myHtml = eregi_replace("-",":",$myHtml);
$myHtml = eregi_replace("<table[^>]*>","<table>",$myHtml);

$myHtml = eregi_replace("<tr[^>]*>","<tr>",$myHtml);
$myHtml = eregi_replace("<td[^>]*>","<td>",$myHtml);
$myHtml = eregi_replace("<img[^>]*>","",$myHtml);
$myHtml = eregi_replace("</?font[^>]*>","",$myHtml);
$myHtml = eregi_replace("</td><td>","~",$myHtml);
$myHtml = eregi_replace("</?tr[^>]*>","",$myHtml);
$strHtml[$k] = $myHtml;
}	

 

which works ok except i have one tag (which changes on each forloop) (ie. new date):

 

<a href="/baseball/mlb/boxscores/2008/03/02/21592_boxscore.html">Box Score</a>

 

which i want to keep the "/2008/03/02/21592" part.

and add an "-" to the front and back

 

like:

"-/2008/03/02/21592-"

 

i have tried this, but i think it is completely wrong...

because it gives me error and because i made up the '-$saved-' part :)

 

$myHtml = eregi_replace("<ahref=\"\/baseball\/mlb\/boxscores(.*?)","-$saved-",$myHtml);

 

thanks

ck

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/96937-replace-part-of-a/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.