Solved

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

Posted on 2015-01-17
4
81 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 110

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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

756 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