Modification of php code in order to fits our demand!
$30-250 USD
Maksettu toimituksen yhteydessä
I need someone to modify the following code in order that it can grab 2 different html pages:
?php
/*
$Id: [url removed, login to view], v1.0 01/16/2008 osC forum - id chris23
Provides courier tracking for Swiss Post
This script will be called via ajax from [url removed, login to view] and admin/[url removed, login to view]
osCommerce, Open Source E-Commerce Solutions
[url removed, login to view]
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
// prevent direct calls to this page
if (!isset($_GET['tracking_id'])) {
die('Direct call to script. Exiting.');
}
require("includes/application_top.php");
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_TRACKING_MODULE);
$tracking_number = $_GET['tracking_id'];
$sp_get_receiver_url = TRACKING_GET_URL_SP;
$params = "&DCSext.wt_shortcut=swisspost-tracking";
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR [url removed, login to view]; InfoPath.1; .NET CLR [url removed, login to view])"; // dummy UA
$url = $sp_get_receiver_url . $tracking_number . $params;
//echo $url; die();
/*
no redirects for ie so grab data and clean
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$grab_data = curl_exec($ch);
if ($error = curl_errno($ch)) {
if ($error == 7) {
die(TRACKING_CURL_SERVER_ERROR);
}
if ($error == 6) {
die(TRACKING_CURL_NO_ACTIVE_INTERNET);
}
}
curl_close($ch);
// tidy extraneous whitespace - use on all grabs
$grab_data = str_replace("n", "", $grab_data);
$grab_data = str_replace("r", "", $grab_data);
$grab_data = str_replace("t", "", $grab_data);
$grab_data = str_replace(" ", "", $grab_data);
$pat[0] = "/^s+/";
$pat[1] = "/s{2,}/";
$pat[2] = "/s+$/";
$rep[0] = "";
$rep[1] = " ";
$rep[2] = "";
$grab_data = preg_replace($pat, $rep, $grab_data);
// set html start and end grab
$StartGrab = '<!--bean:write name="parcelEvent" property="product"/-->';
$EndGrab = '<!-- FINE Packet post-->';
// Grab delivery status information
$text = eregi("$StartGrab(.*)$EndGrab", $grab_data, $content);
// start custom tidying
// strip tags - keep tracking table
$content = strip_tags($content[1], '<table><tr><th></th><td></td></tr></table>');
// remove all html attributes
function strip_attributes($msg, $tag, $attr) {
$lengthfirst = 0;
while (strstr(substr($msg, $lengthfirst), "<$tag ") != "") {
$imgstart = $lengthfirst + strpos(substr($msg, $lengthfirst), "<$tag ");
$partafterwith = substr($msg, $imgstart);
$img = substr($partafterwith, 0, strpos($partafterwith, ">")+1);
$img = str_replace(" =", "=", $msg);
$out = "<$tag";
for($i = 0; $i <= (count($attr) - 1 );
$i++) {
$long_val = strpos($img, " ", strpos($img, $attr[$i]."=")) - (strpos($img, $attr[$i]."=") + strlen($attr[$i]) + 1) ;
$val = substr($img, strpos($img, $attr[$i]."=") + strlen($attr[$i]) + 1, $long_val);
if (strlen($val) > 0) $attr[$i] = " ".$attr[$i]."=".$val;
else $attr[$i] = "";
$out .= $attr[$i];
}
$out .= ">";
$partafter = substr($partafterwith, strpos($partafterwith, ">")+1);
$msg = substr($msg, 0, $imgstart).$out.$partafter;
$lengthfirst = $imgstart+3;
}
return $msg;
}
$content = strip_attributes($content, "tr", array());
$content = strip_attributes($content, "td", array());
$content = preg_replace("/writeBgColor(d{1});/","", $content);
// fix table font size
$content = str_replace("<table border="0" cellpadding="0" cellspacing="0" width="496">","<table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-size: 11px; padding: 5px 0 5px 0;">",$content);
echo $content;
// the following function may be needed if remote server returns utf encoding (parent osC page is iso-8859) - prevents ? characters appearing
// uncomment if returned text contains ? in a little diamond.
echo mb_convert_encoding($output,"UTF-8","ISO-8859-1");
?>
Projektin tunnus: #326659
Tietoa projektista
Myönnetty käyttäjälle:
6 freelanceria on tarjonnut keskimäärin $154 tähän työhön
We have similar projects here, the team with over 7 years working experiences. please kindly check PMB for details, thank you.