?
Solved

cURL search

Posted on 2013-01-16
8
Medium Priority
?
177 Views
Last Modified: 2013-01-16
Hi experts,

I need to use this for more fields with same name and don't know how to search for them.. Please help.

if (substr($str, strpos($str, 'some text')) !== false) {
$string=substr($str, strpos($str, 'fieldname')+10,20);
$string=substr($string, strpos($string, 'blah')+4,20);
$string=substr($string, strpos($string, '>')+1,100);
$string=substr($string, 0, strpos($string, '<'));
}

Thanks.
0
Comment
Question by:jebbie635
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38781780
Can you be little more clear on the scenario, how you are searching..You said curl in heading where is the curl code and how you are searching
0
 

Author Comment

by:jebbie635
ID: 38781822
I guess it's just php. The first part of my script is curl, sorry for that, am newbie. Please tell me how to search for the fields. This is what i want to do:

first search the source code of a page for 'some text', if found continue to search for labels named the same and then get text if label is found. This code is just for the first label which i already know it's there because it found 'some text'.

if (substr($str, strpos($str, 'some text')) !== false) {
$string=substr($str, strpos($str, 'labelname')+10,20);
$string=substr($string, strpos($string, 'blah')+4,20);
$string=substr($string, strpos($string, '>')+1,100);
$string=substr($string, 0, strpos($string, '<'));
}

How do i search for the next label which has the same name as first one? I need to do this for 20 labels.
0
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38782230
read the page and programactically find the list of labels in that page

Then a call a function with required parameters like label,serach term, etc..and return data from that function

Hope its clear
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 35

Expert Comment

by:gr8gonzo
ID: 38782320
Use the Simple HTML DOM library to parse the page - it's going to be far easier and more flexible. I wrote an article on how to use it to manipulate HTML pages, although you can use the same article to simply extract information from a page after you download it with cURL:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_10277-HTML-Manipulation-Made-Easy.html
0
 
LVL 35

Assisted Solution

by:gr8gonzo
gr8gonzo earned 2000 total points
ID: 38782346
The basics are:

// Include the library
require("simple_html_dom.php");

// Assuming $str contains all the HTML from your cURL request
if (strpos($str, 'some text') !== false)
{
   // Parse the HTML
   $html = str_get_html($str);

   // Loop through all <blah> elements
   foreach($html->find("blah") as $blah)
   {
      // Show the contents of that blah tag
      echo "Outertext = " . $blah->outertext . "\n";
      echo "Innertext = " . $blah->innertext . "\n";
      echo "Plaintext = " . $blah->plaintext . "\n";
   }
}
0
 

Author Comment

by:jebbie635
ID: 38783771
$str=post($url, $referer, $agent, $cookie, $vars);

I need to search for this

<div class="someClass">someText</div>

because i have also other <div class="someClass"> with someOtherText which i don't need, and then get the link. I have to do this for 40 possible links.

$link=substr($str, strpos($str, 'someClass')+11,20);
$link=substr($link, strpos($link, 'someText')+14,100);
$link=substr($link, strpos($link, '<a href="')+9,1000);
$link=substr($link, 0, strpos($link, '>'));

Open in new window

This is what i have so far:

$link1=substr($str, strpos($str, 'someClass')+19,20);
$link1=substr($link1, strpos($link1, 'someText')+9,100);
$link1=substr($link1, strpos($link1, '<a href="')+9,1000);
$link1=substr($link1, 0, strpos($link1, '>'));

$link2=substr($str, strpos($str, 'someClass')+19,1000);
$link2=substr($link2, strpos($link2, 'someClass')+9,100);
$link2=substr($link2, strpos($link2, 'someText')+9,100);
$link2=substr($link2, strpos($link2, '<a href="')+9,1000);
$link2=substr($link2, 0, strpos($link2, '>'));
if ($link2) {
some action
}
...
$link40=substr($str, strpos($str, 'someClass')+19,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
...
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someText')+9,100);
$link40=substr($link40, strpos($link40, '<a href="')+9,1000);
$link40=substr($link40, 0, strpos($link40, '>'));
if ($link40) {
some action
}

Open in new window

Can you simplify the search of 'someClass'? This is a lot of code.
0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 2000 total points
ID: 38784792
Try my previous code, but replace this line:

foreach($html->find("blah") as $blah)

with:

foreach($html->find("div.someClass") as $div)

Then you can check the value of $div->plaintext and compare it to "someText" or whatever you're looking for.
0
 

Author Closing Comment

by:jebbie635
ID: 38784959
It works. Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

752 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