preg_match_all help...
Posted: Wed Sep 14, 2005 12:03 am
I have peices of text on the page... Go example:
I want to select those and replace with a link... E.g:
I tried this code but it aint working...
What am I doing wrong?
Code: Select all
{ADDCART:[Rug Only 4|9||-5|6||]PRICE:[82.00]}
{ADDCART:[Rug Only 5|9||-6|]PRICE:[87.00]}Code: Select all
<a href="products/order/cart.php?mode=add&item=Rug%20Only%204|9||-5|6||&price=82.00">Add to Cart</a>
<a href="products/order/cart.php?mode=add&item=Rug%20Only%205|9||-6|&price=87.00">Add to Cart</a>Code: Select all
$match_count = preg_match_all("#\{ADDCART:\[(.*?)\]PRICE:\[(.*?)\]}#si", $body, $matches);
for ($i = 0; $i < $match_count; $i++)
{
$original = "";
$replace = "";
$original = "{ADDCART:[$matches[0]]PRICE:[$matches[1]]}";
$replace = "<a href=\"products/order/cart.php?mode=add&item={$matches[0]}&price={$matches[1]}\">Add to Cart</a>";
$body = str_replace($original, $replace, $body);
}