Search:

Categories



Append a string to a file in PHP

$fp = fopen(“filename”, “a”);
if($fp) {
fwrite($fp, “aString”);
fclose($fp);
}

Remove duplicate elements from array

This shows how to Remove duplicate elements from array using the array_unique function

<?php
$input = array(“a”=>”apple”, “pear”, “b”=>”apple”, “orange”, “melon”);
print_r($input);
$result = array_unique($input);
print_r($result);
?>

Find All Links on a Page

Find All Links on a Page

 

$html = file_get_contents(‘http://www.yahoo.com’);
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate(“/html/body//a”);
for ($i = 0; $i < $hrefs->length; $i++)
{
       $href = $hrefs->item($i);
       $url = $href->getAttribute(‘href’);
       echo $url.’<br />’;
}

Automatically link Twitter usernames in WordPress

/* Automatically link Twitter usernames in WordPress*/
function twtreplace($content) {
$twtreplace = preg_replace(‘/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/’,”$1<a href=\”http://twitter.com/$2\” target=\”_blank\” rel=\”nofollow\”>@$2</a>”,$content);
return $twtreplace;
}
add_filter(‘the_content’, ‘twtreplace’);   
add_filter(‘comment_text’, ‘twtreplace’);

detect if the visitor is on an android device

function isItAndroid()

{

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);

if(stripos($ua,’android’) !== false) return true;

else return false;

}

php search engine

php search engine features include:

Easy to install and configure
Searches all pages on your website
Super fast searching!
No database required – even easier to install!
Finds matching file names (eg: searching for ‘report’ will find a file called ‘latest report .doc‘)
Finds matches in HTML META tags
Finds matches in url’s (eg: searching for ‘products’ will find a file called ‘/website/my- products .html‘)
It will even search INSIDE PDF DOCUMENTS!
The results are sorted by relevance in a page-by-page view similar to Google.
The text that displays under each search result is trimmed to a certain length so it fits on the page nicely.
Any matching keywords in the results are highlighted so the user can see why that result was returned.
Advanced users:
A custom callback function is included so you can insert your own results in with normal HTML results (eg: by querying a database of products for a match).

This makes for great search integration between different products on an existing website.

More Info

http://www.getphp.net/php-search-engine