PDA

View Full Version : regex find and replace



is_numeric
02 Dec 2009, 06:23 AM
hi all

can anyone provide a regex to search through the following html example? This will be a string db extract




<div id="page">
<p class="action">** You must check to see if it is a dormant install.</p>
<h2><span style="font-size: small;"><strong class="alert">Is it a dormant install?</strong></span></h2>
<h1 class="standout">Yes</h1>
<a href="85">this is another link</a>
<h1 class="standout">No</h1>

<a href="86">this is another link</a>
</div>



looking for




<a href="85">
<a href="86">



and replace with



<a href="?pageid=85">
<a href="?pageid=86">



respectively

The 85 and 86 are dynamic and are taken from the find and used in the replace

probably for use with preg_replace()

is_numeric
02 Dec 2009, 08:38 AM
preg_replace("/<a\shref=\"([0-9]+)/" , "<a href=\"?pageid=\\1" , $page[0]);