Web page scraping

The regular expression meta characters we will be using (.*)

The dot (.) stands for any character while the asterisks (*) stands for 0 or more characters. When both are combined (.*) you are letting the system know that you are looking for any set of characters with a length of 0 or more.

we will be using 3 functions in order to extract our data. The first function is our file_get_contents() function which will get the desired page and input all of its contents and html into a string format. The second function we will be using is our preg_match() function which will return us one result when given the regular expression code. The final function we will be using is preg_match_all() which works the same as preg_match() just that preg_match_all() will return more then 1 result.

 

[code]

$url = “index.html”;
$content = file_get_contents($url);
$patten = ‘!(.*)!’;
preg_match_all($patten, $content, $data);
print($data);

[/code]

Example:

Download: scrape

Image upload script

[code]

<?php
$con = mysql_connect("localhost", "root", "");
mysql_select_db("imageupload", $con);
//mysql_query ("insert into ");

if(isset($_POST[‘submit’])){

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
$path = $_FILES["file"]["name"];
mysql_query("INSERT INTO imageinfo(title,path) VALUES (‘$_POST[title]’, ‘$path’)");
}
else
{
echo "Invalid file";
}
}
$result = mysql_query(‘SELECT *FROM imageinfo’);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table cellpadding="5" cellspacing="5">
<tr bgcolor="#CCCCCC">
<td>ID</td>
<td>Picture</td>
<td>Title</td>
</tr>
<?php    while ($row = mysql_fetch_array($result)){ ?>
<tr bgcolor="#CCCCCC">
<td><?php echo $row[0]; ?></td>
<td><img src="upload/<?php echo $row[1]; ?>" alt="" /></td>
<td><?php echo $row[2]; ?></td>
</tr>
<?php }?>
</table>
<form action="" method="post" enctype="multipart/form-data">
Title: <input type="text" name="title" id="title" /></br>
Upload: <input type="file" name="file" id="file" /><input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

[/code]

Download: imageupload

UPS shipping problem for osCommerce

Solution:

Locate: catalog -> includes -> module -> shipping -> usps.php  (about line 95)

[code] list($type, $cost) = each($uspsQuote[$i]); [/code]

Add these lines after it

[code]

$type = str_replace(‘&amp;lt;sup&amp;gt;&amp;amp;reg;&amp;lt;/sup&amp;gt;’, ”, $type);
$type = str_replace(‘&amp;lt;sup&amp;gt;&amp;amp;trade;&amp;lt;/sup&amp;gt;’, ”, $type);
$type = str_replace(‘**’, ”, $type);

[/code]

Paypal solution

Problem: Unable to process payment. Please contact the merchant as the shipping address provided by the merchant is invalid, and the merchant has requested that your order must be shipped to that address.

Solution:

Admin->Modules->Payment->PayPal Website Payments Standard->Edit, and change Address Override from 1 to 0

in the file plugins/paypal/paypal.php
please comment this line ( in the function plgVmConfirmedOrder

[code]"address_override" => "1",[/code]

In the next version, this parameter will be set via the Paypal configuration.

This parameter sets the overriding addresses stored with PayPal
For people who already have PayPal accounts and whom you already prompted for a shipping address before they choose to pay with PayPal, you can use the entered address instead of the address the person has stored with PayPal.

Error 503: Service Unavailable

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Solution:

There are two main reasons why you may get this error.

1. There is an actual problem with the server, resulting in the 503 error response. In this case, you should contact your hosting provider.

2. Your store has been put in maintenance mode. If Magento sees a file named maintenance.flag in the root directory, it will automatically redirect all requests to the default 503 error page. This can be used during upgrades, etc. to prevent users from accessing the store. The solution is, as already mentioned, to delete/rename the maintenance.flag file.

There might also be a good idea to create a more user friendly “maintenance page” than the 503 error, which is kind of misleading for customers.