Jump to content


Simple Fix?

  • Please log in to reply
No replies to this topic

#1 mnybud

  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 30 August 2006 - 02:55 PM

I have this Wordpress plugin code (shown below) that pulls definitions from Google. I just call it in my wordpress posts as ~GetDEF(Your_Search_Term)~ and it works great as long as Google has a definition for the term inputed. If Google does not have a definition then it just prints ~GetDEF(Your_Search_Term)~ instead which is kind of ugly.

I am wondering is there a way to make it so it displays nothing if the term is not found?

I dont know much about PHP so if anyone can help please tell me what I should use to stop this and where I should put it in the code. If you need more info please let me know. Thanks in advance!!

Here is the plugin code, its just one php file:

//Server Configuration
$host = "www.google.com";

function getDEF( $def ) {
    global $host,$searchStr,$path;
    $fp = fopen ($searchStr.$def, "r");
  if (!$fp) {
  $contents ="";
  while (!feof ($fp)) {
      $contents .= fread($fp, 8192);
  if (eregi ("<ul type=\"disc\">(.*)</ul>", $contents, $out)) {
      $article = $out[1];
if (eregi ("<li>(.*)<li>", $contents, $out)) {
      $article = $out[1];

$description=  "</br><span class=\"gdescription\">
This definition of ".$def.' is provided by the best search engine in the world, Google!</span>';
$article = "<div class=\"Gdef\">".$def.":
return $article;

function def_fy( $text ) {
    $text = preg_replace(

return $text;

function def_css() {
    echo "
    <style type='text/css'>
    div.Gdef {
        border: 1px dashed silver;
        background-color: #f0f0f0;
  padding:0 2em 0 2em;
    .gdescription {
        font-size: 80%;
      padding:0 2em 0 2em;

add_action('wp_head', 'def_css');
add_filter('the_content', 'def_fy', 2);
add_filter('the_excerpt', 'def_fy', 2);

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users