Archive for category PHP code
Declare new array php
Posted by in PHP code on October 20th, 2011
You can declare new array in PHP by using the code below:
$new_array = array();
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.
Cross-Site Scripting
Posted by in PHP code on February 7th, 2011
Here’s a nice tutorial:
http://www.xssed.com/article/6/Paper_Kr3ws_Cross-Site_Scripting_Tutorial/
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();
?>
Import Mochimedia Feed
Posted by in PHP code on July 21st, 2010
Just make a code for importing Mochimedia game feed.
It will import the feed by creating post, add tag, insert into category, and schedule it dailly. It is using wordpress technology. You need to put these files in wp root.
Download it here.









