Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Senior Member
    Join Date
    Aug 2011
    Posts
    170
    Member #
    29153
    Liked
    2 times
    If I have a lot of content stored in a variable, how do I find each occurrence of a certain word. For example, I want to find the word grand and then grab the word that follows it.

    Basically, I want to check each time the word grand is used then save the following word in my database.

    Let's say I set it up like this.

    $story = "The princess went to the grand ball by herself. She was waring a yellow dress and grand shoes. While there, she dance with lots of men but one was a grand prince. He lived another village in a grand castle."

    So, I need to run some sort of a for loop that is going to pick out the words "ball", "shoes", "prince", and "castle".

    How can I do this?

  2.  

  3. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    170
    Member #
    29153
    Liked
    2 times
    maybe I need to just say exactly what I want instead of an example like that. I need to have the code of some web pages, which I already can get, and find each time a link to the page somesite.com/this/##### where the "#####" is different each time. I need to save all of the different "#####" to my database. Of coarse the code would be something like <a href="this/B126P">

    So, basically I would need to look for all occurrences of "<a href=\"this/" and grab the next 5 characters.

  4. #3
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,324
    Member #
    27709
    Liked
    764 times
    Why just the next five characters ?

    Looks like a link scraping script... Tons on them on the Internet... Found one the other night for a project I'm working on... Inserts all links into a DB as well.

    Is that what you're looking for ?

  5. #4
    Senior Member
    Join Date
    Aug 2011
    Posts
    170
    Member #
    29153
    Liked
    2 times
    Basically that's what I need. I'll be using it to grab lots of things from those pages. I have an affiliate program set up and I need to get prices, images, etc. I can get these once I can search all of the pages and grab their links.

  6. #5
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,324
    Member #
    27709
    Liked
    764 times
    This is the one I used... Of course you will
    Need to add the DB table and authentication....

    http://www.phpbuilder.com/columns/marc_plotz011410.php3

  7. #6
    Senior Member
    Join Date
    Aug 2011
    Posts
    170
    Member #
    29153
    Liked
    2 times
    I'm at work right now so I will check it out when I get home.

    Thanks!

  8. #7
    Senior Member
    Join Date
    Aug 2011
    Posts
    170
    Member #
    29153
    Liked
    2 times
    Here's what I have.

    // $i is for the node to go to all pages and grab links
    for($i=1; $i<=25; $i++) {

    $categoryPageUrl = "http://astore.amazon.com/luv2kayak-20?node=" . $node . "&page=" . $i;

    // $x is a counter to get each of the 10 item numbers on a page
    for($x=1; $x<=10; $x++) {

    $html = file_get_contents($categoryPageUrl);
    $start = strpos($html, "luv2kayak-20/detail") + 20;
    $end = strpos($html, "luv2kayak-20/detail") + 30;
    $itemNum = substr($html, $start, $end-$start);

    echo $itemNum, "<br>";
    }
    }

    The output here gives me the same characters for the $itemNum even though there are 10 on each page. How do I get it to move to the next one each time it reads what I am telling it to?

  9. #8
    Senior Member
    Join Date
    Aug 2011
    Posts
    170
    Member #
    29153
    Liked
    2 times
    Just changed, but still doing the same thing.

    for($i=1; $i<=25; $i++) {

    $categoryPageUrl = "http://astore.amazon.com/luv2kayak-20?node=" . $node . "&page=" . $i;
    $html = file_get_contents($categoryPageUrl);


    // $x is a counter to get each of the 10 item numbers on a page
    for($x=1; $x<=10; $x++) {

    $start = strpos($html, "luv2kayak-20/detail") + 20;
    $end = strpos($html, "luv2kayak-20/detail") + 30;
    $itemNum = substr($html, $start, $end-$start);

    echo $itemNum, "<br>";


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:19 AM.
Powered by vBulletin® Version 4.2.0
Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com