[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

cURL search

Posted on 2013-01-16
8
Medium Priority
?
178 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
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.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 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