# I pay 70$ via paypal for a simple php script thant can:

**URL:** <https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859>\
**Category:** PHP Freelancing\
**Created:** [June 13, 2014, 1:14pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859 "2014-06-13T13:14:12Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [June 13, 2014, 9:26pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/21 "2014-06-13T21:26:19Z")

</div>

You already did! It is nice to hear thanks.

So, test that new version and let me know if you get new errors.

---

<div class="post-metadata">

**Author:** ![nejah911](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nejah911](https://www.phphelp.com/u/nejah911)\
**Post date:** [June 13, 2014, 9:27pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/22 "2014-06-13T21:27:13Z")

</div>

ok

---

<div class="post-metadata">

**Author:** ![nejah911](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nejah911](https://www.phphelp.com/u/nejah911)\
**Post date:** [June 15, 2014, 11:47am UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/23 "2014-06-15T11:47:59Z")

</div>

Yeesssssssss!!! finally it works for me on my local server and that’s good enough.  
only problorem is that dont work for other pages of aliexpress ☹

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [June 15, 2014, 3:53pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/24 "2014-06-15T15:53:31Z")

</div>

Well, Nejah, the problem with pulling information from other sites is that they change as they wish.  
What that means is that they may use different routines to display their data depending on various  
display options. Therefore, it can be very hard to lock onto the exact image you want to pull out.

In my code I sent to you, I was working on only one page from their site. I also had the smaller image  
by mistake. Here is a better version that loads the larger picture and displays it. Since you are planning  
to use the images to sell their products, I do not think there is any copyright issues.

Also, note that with this code, you can pull just about anything you need from their catalog pages. But, in  
most cases, you might have alter what you are looking for. This is done in the STRPOS areas. You will see  
that to locate the larger image, I had to do it in two steps. First, locating the area where the image is  
stored and then locating the actual ![]() string.

Good luck with your new business… Ernie  
[php]

\<?PHP // The next two lines are to show all errors, remove after testing error\_reporting(E\_ALL); ini\_set('display\_errors', 1); // Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an array containing the HTTP server response header fields and content. // This is a CURL function which grabs the page for you function get\_web\_page( $url ) { $user\_agent="Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 "; $options = array( CURLOPT\_CUSTOMREQUEST =\>"GET", //set request type post or get CURLOPT\_POST =\>false, //set to GET CURLOPT\_USERAGENT =\> $user\_agent, //set user agent CURLOPT\_COOKIEFILE =\>"cookie.txt", //set cookie file CURLOPT\_COOKIEJAR =\>"cookie.txt", //set cookie jar CURLOPT\_RETURNTRANSFER =\> true, // return web page CURLOPT\_HEADER =\> false, // don't return headers CURLOPT\_FOLLOWLOCATION =\> true, // follow redirects CURLOPT\_ENCODING =\> "", // handle all encodings CURLOPT\_AUTOREFERER =\> true, // set referer on redirect CURLOPT\_CONNECTTIMEOUT =\> 120, // timeout on connect CURLOPT\_TIMEOUT =\> 120, // timeout on response CURLOPT\_MAXREDIRS =\> 10, // stop after 10 redirects ); $ch = curl\_init( $url ); curl\_setopt\_array( $ch, $options ); $content = curl\_exec( $ch ); $err = curl\_errno( $ch ); $errmsg = curl\_error( $ch ); $header = curl\_getinfo( $ch ); curl\_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } // Read the web page and check for errors: $url = "http://fr.aliexpress.com/item/1pcs-lot-Portable-Sonar-LCD-Fish-Finder-Alarm-100M-AP-ice/410762949.html"; $result = get\_web\_page( $url ); if ( $result['errno'] != 0 ) echo "... error: bad url, timeout, redirect loop ..."; if ( $result['http\_code'] != 200 ) echo "... error: no page, no permissions, no service ..."; $page = $result['content']; // We now have the page, locate the picture and price inside it. First finde the image area on page... $start = strpos($page, '
'); $start2 = strpos($page, '", $start2) + 2; // This item minus one for end of previous item... $picture = substr($page, $start2, $end-$start2); // Place this text into \<\>'s and it will display on site... echo "  
". $picture . "  
"; // We have the picture image text, now capture the price $start = strpos($page, '') + 52; // This item plus the length of it... $end = strpos($page, "", $start); // This item minus one for end of previous item... $price = substr($page, $start, $end-$start); // Place this text into \<\>'s and it will display on site... echo "  
". $price . "  
"; ?\>

[/php]  
One last thought, This is set up with a hard-coded $URL string that points at the page. You would want  
to create some sort of routine to locate the item and then allow you to call this routine automatically.

---

<div class="post-metadata">

**Author:** ![nejah911](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nejah911](https://www.phphelp.com/u/nejah911)\
**Post date:** [June 15, 2014, 5:52pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/25 "2014-06-15T17:52:14Z")

</div>

Hi again  
yes the script work graet with that URL but not for all URL and after a long search I discovered that:  
----- “imageURL”: [ ----- is always before jpg file  
----- US $----- is always before the total price.

that mean we have to take these 2 text in consideration to make the script work for all pages

see file in attachment

* * *

[ali express full exemple.txt](https://www.phphelp.com/uploads/default/original/2X/4/4ff9ad88ecbcdbe909b8708754382f86cfcc4514.txt) (54 KB)

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [June 16, 2014, 1:43pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/26 "2014-06-16T13:43:32Z")

</div>

Nejah,

This format is a bit different due to it being inside the Javascript code. This is where they show the  
float-over zoom-in area on their site. So, the formatting is just a little different.  
The following pulls both the picture and price from that area.

Hope that helps. Here is the new version:  
[php]

\<?PHP // The next two lines are to show all errors, remove after testing error\_reporting(E\_ALL); ini\_set('display\_errors', 1); // Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an array containing the HTTP server response header fields and content. // This is a CURL function which grabs the page for you function get\_web\_page( $url ) { $user\_agent="Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 "; $options = array( CURLOPT\_CUSTOMREQUEST =\>"GET", //set request type post or get CURLOPT\_POST =\>false, //set to GET CURLOPT\_USERAGENT =\> $user\_agent, //set user agent CURLOPT\_COOKIEFILE =\>"cookie.txt", //set cookie file CURLOPT\_COOKIEJAR =\>"cookie.txt", //set cookie jar CURLOPT\_RETURNTRANSFER =\> true, // return web page CURLOPT\_HEADER =\> false, // don't return headers CURLOPT\_FOLLOWLOCATION =\> true, // follow redirects CURLOPT\_ENCODING =\> "", // handle all encodings CURLOPT\_AUTOREFERER =\> true, // set referer on redirect CURLOPT\_CONNECTTIMEOUT =\> 120, // timeout on connect CURLOPT\_TIMEOUT =\> 120, // timeout on response CURLOPT\_MAXREDIRS =\> 10, // stop after 10 redirects ); $ch = curl\_init( $url ); curl\_setopt\_array( $ch, $options ); $content = curl\_exec( $ch ); $err = curl\_errno( $ch ); $errmsg = curl\_error( $ch ); $header = curl\_getinfo( $ch ); curl\_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } // Read the web page and check for errors: $url = "http://fr.aliexpress.com/item/1pcs-lot-Portable-Sonar-LCD-Fish-Finder-Alarm-100M-AP-ice/410762949.html"; $result = get\_web\_page( $url ); if ( $result['errno'] != 0 ) echo "... error: bad url, timeout, redirect loop ..."; if ( $result['http\_code'] != 200 ) echo "... error: no page, no permissions, no service ..."; $page = $result['content']; // We now have the page, locate the picture and price inside it. First finde the image area on page... $start = strpos($page, '"imageURL": ['); $start2 = strpos($page, 'http:', $start); // This item plus the length of it... $end = strpos($page, ".jpg", $start2) + 4; // This item minus one for end of previous item... $picture = substr($page, $start2, $end-$start2); // Place this text into \<\>'s and it will display on site... echo "  
 ![]()  
"; // We have the picture image text, now capture the price $start = strpos($page, 'skuPrice', $start2) + 11; // This item plus the length of it... $end = strpos($page, '"', $start); // This item minus one for end of previous item... $price = substr($page, $start, $end-$start); // Place this text into \<\>'s and it will display on site... echo "  
". $price . "  
"; ?\>

[/php]  
So, this version should work nicely for you. Hope it helps. If so, we can mark this one solved.  
Of course, we look forward to your next question. Glad we could help…

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [June 16, 2014, 9:05pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/27 "2014-06-16T21:05:07Z")

</div>

Did that new version work for you? Just curious…

---

<div class="post-metadata">

**Author:** ![nejah911](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nejah911](https://www.phphelp.com/u/nejah911)\
**Post date:** [June 16, 2014, 9:24pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/28 "2014-06-16T21:24:45Z")

</div>

hi friend  
Finally I understood you php magic !!  
I made a page that pick up price and weight and another one to pick images and it work fine until now  
[php]

$begin = strpos($page, ‘\<dd class=“pnl-packaging-size” rel’) +32;

$begin2 = strpos($page, ‘=’ ,$begin) +2; // This item plus the length of it…  
$end = strpos($page, “\>”, $begin2) -1; // This item minus one for end of previous item…  
$packing = substr($page, $begin2, $end-$begin2); // Place this text into \<\>‘s and it will display on site…  
$packing=str\_replace(’|’,’ cm\* ',$packing);  
echo “$packing cm”;

$begin = strpos($page, ‘pnl-packaging-weight" rel’) ;  
$begin2 = strpos($page, ‘="’ ,$begin) +2; // This item plus the length of it…  
$end = strpos($page, “\>”, $begin2) -1; // This item minus one for end of previous item…  
$weight = substr($page, $begin2, $end-$begin2); // Place this text into \<\>'s and it will display on site…  
echo $weight;

[/php]

---

<div class="post-metadata">

**Author:** ![nejah911](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nejah911](https://www.phphelp.com/u/nejah911)\
**Post date:** [June 16, 2014, 9:25pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/29 "2014-06-16T21:25:37Z")

</div>

Thanks a lot my friend, you a genius 😛

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [June 16, 2014, 9:31pm UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/30 "2014-06-16T21:31:27Z")

</div>

Congratulations on getting it to work. Glad I could help. Now go and make some money with it!

I will mark this one closed. When you run into another issue, please start a new post. Glad to meet you!

---

<div class="post-metadata">

**Author:** ![nejah911](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nejah911](https://www.phphelp.com/u/nejah911)\
**Post date:** [June 17, 2014, 8:12am UTC](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859/31 "2014-06-17T08:12:39Z")

</div>

Thanks a lot, your forum is the best ever

[Previous page](https://www.phphelp.com/t/i-pay-70-via-paypal-for-a-simple-php-script-thant-can/22859.md?page=1)
