Recently I was working with a database and needed a way to have variables on each page but each page needed different content. i know this can be done with templating but I didn't want to have to import a big templating software for this one thing. I did a few searches online and after a while of searching saw mention of PhP's eval function.
It was a bit tricky to get working but here is the result:
eval("\$string = \"$string\";");
echo $string;
$string is the result from the database and can contain a string like "we have $variable1 for your $variable2!". The eval function takes car of parsing the PhP variable...very useful.
Thought this might be useful to anyone caring to read =)
Thursday, November 20, 2008
Gmail's New Themes
So I originally heard about the new themes for Gmail and thought well that's pretty cool that they,re finally doing that. But I decided to check it out and the last theme caught my eye - Terminal. A little something every programmer can appreciate...
check it out by going to Gmail Themes and logging to your gmail account
check it out by going to Gmail Themes and logging to your gmail account
Thursday, November 6, 2008
Site Keyword Crawler
Recently I have been interested in PhP array functions and Regular Expressions (abbreviated as RegExp). I have found it is very easy to find the major keywords that are inside a string of text using the following code:
Basically it breaks apart the content into an array of tokens and checks for duplicates. As it stands this will grab anything with a space between as a token so things like 'alt="text' will be tagged as a token. Some modifications are needed for this to work on an HTML document like some fancy reg exp searches =). I will keep posting with any updates to this function...
function getKeyWords($content){
$tokens=explode(" ", $content);
$keywords=array("num_words"=>1);
foreach ($tokens as $word){
if (!array_key_exists($word, $keywords)){
//echo "word not found! $word
";
$keywords[$word]=1;
}else
$keywords[$word]++;
$keywords['num_words']++;
}
return $keywords;
}
Basically it breaks apart the content into an array of tokens and checks for duplicates. As it stands this will grab anything with a space between as a token so things like 'alt="text' will be tagged as a token. Some modifications are needed for this to work on an HTML document like some fancy reg exp searches =). I will keep posting with any updates to this function...
Subscribe to:
Posts (Atom)