Posts Tagged Lt
preg_replace to replace all href
Posted by in PHP code on July 7th, 2011
Here’s a good one
$pattern = "/as+hrefs*=s*['\"]?([^'\">]+)['\"]?>([^<]*)</ie";
$replacement = "'a href=\"$1'.strtolower(str_replace(' ', '', '$2')).'\">$2<'";
$string = preg_replace($pattern, $replacement, $string);
The pattern says to find:
- ‘a href‘ — there must be at least one space in between the ‘a’ and the ‘href‘ ( \s+ ),
- followed by zero or more spaces( \s* ),
- followed by the equal sign ( = ),
- followed by zero or more spaces ( \s* ),
- followed by an optional single quotation mark or double quotation mark ( ['\"]? ),
- followed by one or more of anything that is not a single quotation mark, a double quotation mark or an end element marker and capture this subpattern by using parentheses ( ([^'\">]+) ),
- followed by an optional closing single quotation mark or double quotation mark ( ['\"]? ),
- followed by a closing element marker ( > ),
- followed by zero or more of anything that is not an opening element marker ( ([^<]*) ),
- followed by an opening element marker.
Uploading a file using Curl in PHP
Posted by in PHP code on November 15th, 2010
Here’s how to upload files using curl in php: (it’s very easy)
notice the @ infront of the file path, this is the magic part.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
curl_setopt($ch, CURLOPT_POST, true);
// same as <input type="file" name="file_box">
$post = array(
"file_box"=>"@/path/to/myfile.jpg",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
?>
Source: http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html
Permanet Redirect in PHP
Posted by in PHP code on August 6th, 2010
<?php
// Permanent redirection
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://www.website.com/”);
exit();
?>
PayPal Subscriptions HTML Code
Posted by in PHP code on January 6th, 2010
Manipulating The HTML Code for Your Subscription Button
The following tables show the different parameters within the Subscriptions HTML code and the Subscriptions hyperlink.
The terms for the following subscription are:
-Free for the first week
-$5.00 USD for the next 2 months
-$50.00 USD per year thereafter. Recurs at regular rate for 5 payments
border=”0″ name=”submit”
alt=”Make payments with PayPal – it’s fast, free and secure!”>
|
Table 9.1
|
Source: https://www.paypal.com/en_US/ebook/subscriptions/html.html
Autoscroll with PHP
Posted by in PHP code on October 16th, 2009
Here’s the code for auto scroll with php:
.scrollbar {
height: 70px;
overflow: auto;
width:100px;
}
</style>
<div class=scrollbar>
money <br />
stock<br />
finance<br />
option<br />
forex<br />
currency<br />
loan<br />
Accessing other frame data
Posted by in PHP code on July 29th, 2009
In your main page you have an iframe. The iframe code is:
To access the data from that iframe the syntax will be :
Formname.document.getElementsByName.(‘contaolname’)[0].value
So the code for the main file is:
function getvalue()
{
alert(frame1.document.getElementsByName(‘myname’)[0].value);
}
</script>
<iframe src=”form.php” name=”frame1″></iframe>
<input type=”button” value=”Get value” onclick=”getvalue()”>
Prevent sql injection code
Posted by in PHP code on July 23rd, 2009
SQL Injection is a technique where an attacker creates or alters existing SQL commands to tamper data, override valuable ones, or even to execute dangerous system level commands on the database host. To avoid this, always check your input data using the function below:
{
$valid_string = “[\*\^\'\;]“;
if(ereg($valid_string,$str))
{
echo(“<script>alert(‘Invalid characted’);</script>”);
die();
}
else
{
return $str;
}
}
Show code to wordpress home only
Use this code to show only to home page only on wordpress:
//your code here
<?php endif; ?>









