Solved

How to process arrays from <textarea> in php script?

Posted on 2008-06-25
3
391 Views
Last Modified: 2010-04-21
Hello, I have php application that process URL and KEYWORD to get me information about site position in Google search page. For example when I type www.cars.com and keyword audi, application connect to the Google and tell me www.cars.com is on the position number 4 with keyword audi.

But I need to process in application more keywords at one time. I have script listed below that make arrays from lines in <textarea>, but I dont know how to edit main script.

For example, URL will be www.cars.com and keywords will be:
audi
bmw
skoda

and script will get me informations:
audi position 3, bmw position 5, skoda position 8

I hope you help me. And sorry for poor level of english.
<?

             $data = $_POST["text"];

 

		$data_array = explode("\n", $data);

				

		$arrayKeys = array_keys($data_array);

				

		for ($i=0; $i<count($data_array); $i++) {

		echo $data_array[($arrayKeys[$i])] . "<br />";

				}

 

?>

 

 

<?

    $engine="Google.sk";

 

    $serp="http://www.google.sk/search?q=<%key%>&hl=sk&btnG=Hladat+v+Google&num=<%num%>&sa=N";

 

    $splitter="<div class=g";

 

    $num=$HTTP_POST_VARS['num'];

 

    $search_url=str_replace('<%key%>', urlencode($HTTP_POST_VARS['key']), $serp);

                   $search_url=str_replace('<%num%>', urlencode($num), $search_url);

                   $lines = file_get_contents($search_url);

                   $sections = split($splitter, $lines);

 

                $pos[$engine]=0;

                   foreach ($sections as $key => $value) {

                         if (strpos($value, $HTTP_POST_VARS['url'])) {

                         $pos[$engine]=$key;

                          break;}

                         }

                }

                         

                if ($pos[$engine]==0) {$pos[$engine]="-";}

 

    Position on Google.sk: <?php echo $pos[$engine] ?>

                 <br>             

                 Keyword: <?php echo $HTTP_POST_VARS['key'] ?>

 

 

 

?>

Open in new window

0
Comment
Question by:MrHusar
3 Comments
 
LVL 13

Accepted Solution

by:
MasonWolf earned 250 total points
ID: 21879579
Try this. I'm heading out, so I won't be available to offer further support right away - might be back on tomorrow evening. Hopefully if it doesn't work on the first try someone else can get you the rest of the way.
<?

    $engine="Google.sk";

?>

Position on Google.sk: <br />

<ul>

<?

$keys = explode("\n",$_POST['text']);

foreach($keys as $key) {  $search_url=sprintf("http://www.google.sk/search?q=%s&hl=sk&btnG=Hladat+v+Google&num=%d&sa=N",urlencode($key),urlencode($_POST['num']));

 

    $splitter="<div class=g";

    $lines = file_get_contents($search_url);

    $sections = split($splitter, $lines);

 

    $pos[$engine]=0;

    foreach ($sections as $key1 => $value) {

        if (strpos($value, $HTTP_POST_VARS['url'])) {

             $pos[$engine]=$key1;

             break;

        }

    }

    if ($pos[$engine]==0) {$pos[$engine]="-";}

    echo "<li> $key position {$pos[$engine]}</li>";

}

?>

</ul>

Open in new window

0
 

Author Closing Comment

by:MrHusar
ID: 31470776
Thank you very much, works perfect. Iam very satisfied! Have a nice day :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now