War Room

Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Featured Warrior Special Offer...
"Members Of The *War Room* Discover Secrets To Immediate Success!"
Reply
 
LinkBack Thread Tools
Old 07-19-2009, 10:40 AM   #1
Gene Yarbrough
War Room Member
 
Join Date: Oct 2005
Location: Northern Virginia
Posts: 476
Thanks: 18
Thanked 31 Times in 19 Posts
Contact Info
Send a message via Skype™ to gyar29
Default Pull specific data from url string via php??

I have a form that I'm using to post to a php script that populates a MySql database. One of the form fields is a URL. I'd like to pull specific information from the URL string and use that info as a unique id in the database.

Below you'll find an example of what I'm wanting to accomplish. The info I'd like to pull from the URL is in red font. It will be used as the unique product ID in the database.

An example URL:
Code:
h**p://somesite.com/productcategory/111111-a-specific-name-for-the-product
Of course it may be better to just generate a unique Product ID when populating the database. However, the numbers in the URL string are already unique. They are already specific to that product. They are generated by a separate script when the URL is generated so changing them is not an option. And keeping one set of product ID numbers for each product just seems to make sense.

Of course, if those of you with more experience than I are of the opinion that I'm trying to re-invent the wheel here, then I'll surrender to your wisdom and just generate another product ID when populating the database.

Thanks for the help,
Gene
gyar29 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-19-2009, 01:43 PM   #2
Active Warrior
 
Join Date: Jul 2009
Location: Pennsylvania, US
Posts: 30
Thanks: 2
Thanked 10 Times in 9 Posts
Lightbulb Re: Pull specific data from url string via php??

Gene,

As long as the URL format doesn't change, this will do it for you...

PHP Code:
<?php
$product_id 
$reg_results null;
$incoming_url 'h**p://somesite.com/productcategory/12345-a-specific-name-for-the-product';
$regexp '/([0-9]+)-';

if (
eregi($regexp$incoming_url$reg_results))
{
    if (
is_array($reg_results) && sizeof($reg_results) > 1)
    { 
$product_id = (int) $reg_results[1]; }
}

if (
$product_id 0)
{
    
# do your stuff here, using $product_id
}
?>
The relevant part is really the eregi() call and then the setting of $product_id from the resulting eregi()'s $reg_results array. It's wrapped in conditions for security & to keep it from throwing errors on strange results.

To growth and success,

Max Leadford

Hit the Thanks in the lower right if you found this post useful. Thanks! ;-)
How To Get Leads, Conversion & Cashflow Using Passive (FREE!) Promotion - 8 Part eCourse Spills the Beans
Serial Ramblings of an Entrepreneur
Kiva.org - Help aspiring entrepreneurs by giving low sum loans.
maxleadford is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to maxleadford For This Useful Post:
Old 07-19-2009, 11:11 PM   #3
Gene Yarbrough
War Room Member
 
Join Date: Oct 2005
Location: Northern Virginia
Posts: 476
Thanks: 18
Thanked 31 Times in 19 Posts
Contact Info
Send a message via Skype™ to gyar29
Default Re: Pull specific data from url string via php??

Max,

Excellent! Thanks for the time you spent on this.

Take Care,
Gene
gyar29 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-21-2009, 08:31 PM   #4
Active Warrior
 
Join Date: Jul 2009
Location: Pennsylvania, US
Posts: 30
Thanks: 2
Thanked 10 Times in 9 Posts
Default Re: Pull specific data from url string via php??

Gene,

You're welcome. Good luck on your project!


To growth and success,

Max Leadford

Hit the Thanks in the lower right if you found this post useful. Thanks! ;-)
How To Get Leads, Conversion & Cashflow Using Passive (FREE!) Promotion - 8 Part eCourse Spills the Beans
Serial Ramblings of an Entrepreneur
Kiva.org - Help aspiring entrepreneurs by giving low sum loans.
maxleadford is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
data, php, pull, specific, string, url

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 11:54 AM.