?
Solved

How do I fix this preg-match-all For Each

Posted on 2015-01-17
4
Medium Priority
?
87 Views
Last Modified: 2015-01-17
This preg_match_all statement works, however when the URL is imported into the database it looks like:
http://www.website.com/brand/airfonix/1   

I am assuming that the "1" is the $key...

How do I make the URL look like:

http://www.website.com/brand/airfonix/All      // (Without the "1")

instead of
 
http://www.website.com/brand/airfonix/1


$statement = $conn->prepare('INSERT IGNORE INTO Websiteurldownload (BrandURL) VALUES(:URL)');

preg_match_all('%<td width="13" height="30" align="left" valign="top"><a href="(.*?)">%',$buffer2,$matches1);


foreach($matches1[0] as $key=>$link){
	$params = array(':URL'=>"http://www.website.com/".$matches1[1][$key]);
        //$params = array(':URL'=>"http://www.website.com/".$matches1[1][$key]."/All");   
	$statement->execute($params); 
}

Open in new window

0
Comment
Question by:lawrence_dev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40555372
<?php // temp_lawrence_dev.php
error_reporting(E_ALL);

/** 
 * Replace the ending digits with the word "All"
 */
$url = 'http://www.website.com/brand/airfonix/1';
$rgx
= '#'       // REGEX DELIMITER
. '[0-9]'   // CHARACTER CLASS DIGITS
. '$'       // AT THE END OF THE DATA
. '#'       // REGEX DELIMITER
;
$new = preg_replace($rgx, 'All', $url);

var_dump($url, $new);

Open in new window

0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 40555378
Try replacing line 3 with this:
preg_match_all('%<td width="13" height="30" align="left" valign="top"><a href="(.*)/.*?">%',$buffer2,$matches1);

This should give you the URL, minus the part after the last "/".

HTH,
Dan
0
 

Author Closing Comment

by:lawrence_dev
ID: 40555533
Simple t figure out.  Thanks for your help!
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40555577
You're welcome.
Glad I could help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question