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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.