Jump to content


This topic is now archived and is closed to further replies.


Simple Problem?

Recommended Posts

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);

Share this post

Link to post
Share on other sites
[b]Stop [/b]double-posting.

If our forum rules are too hard to follow, perhaps you would feel happier elsewhere.

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.