WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : The GTV.class allows you to extract a value between any HTML tag or between any TEXT on a web page.
Categories : PHP, PHP Classes, Regexps Click here to Update Your Picture
naifphp naif php
Date : Jul 24th 2007
Grade : 3 of 5 (graded 4 times)
Viewed : 5596
File : 4678.zip
Images : No Images for this code example.
Search : More code by naifphp naif php
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

GTV.class.php
<?php
/***************************************************************************
============================================================================
| @ Script Name             : Get Tag Value
| @ Version                 : 1.0
| @ Description             : Get The Tag Value .
| @ All rights reserved to  : NaiF PHP
| @ Created In              : 09-07-2007
| @ Support             : wald_al_dala@hotmail.com
============================================================================
****************************************************************************/

class GTV
{

   
# Public #
   
var $path;
   var
$start_tag;
   var
$end_tag;

   
# Private #
   
var $tag_value;
   var
$conts = "";
   var
$DefineError = array(
                           
" please enter the start and the end of the requested tag",
                           
" the start tag must be the same as the end tag",
                           
" please enter the url of the page you want request tags from ",
                           
" unable to reach the requested page ",
                           
" sorry .. unable to get the requested tags ",
                           
" error .. the starting and ending tags must be an array "
                           
);


   
// to start find you tag value ...
   
function GTV($path,$start_tag,$end_tag)
   {
     
$this->path = $path;
     
$this->start_tag = $start_tag;
     
$this->end_tag = $end_tag;

      if(empty(
$this->start_tag) || empty($this->end_tag))
      {
         
$this->tag_value = $this->DefineError[0];
      }
      else
      {
         @
set_time_limit(0);
         
$this->tag_value = $this->GetTagValue();
      }

     return
$this->tag_value;
   }

   
// fro find your tag & return value him
   // array or one tag(s)
   
function GetTagValue()
   {
       if((
$_cont = $this->LoadPage()) != $this->DefineError[2])
       {
          if(
is_array($this->start_tag) && is_array($this->end_tag))
          {
             foreach(
$this->start_tag as $id=>$tag)
             {
               
$ST = $this->start_tag[$id];
               
$ET = $this->end_tag[$id];

                if(
$this->check($ST,$ET) == false)
                {
                   
$__res = $this->DefineError[1];
                }
                else
                {
                   
preg_match( "/$ST(.*)$ET/s", $_cont, $match );

                   
$__res[] = htmlspecialchars($tag) .' :: '. (is_null($match[1]) ? $this->DefineError[4] : htmlspecialchars($match[1]));
                }
             }
          }
          else if(
is_array($this->start_tag) || is_array($this->end_tag))
          {
             
$_res = $this->DefineError[5];
          }
          else
          {
              if(
$this->check($this->start_tag,$this->end_tag) == false)
              {
                 
$__res = $this->DefineError[1];
              }
              else
              {
                 
preg_match( "/$this->start_tag(.*)$this->end_tag/s", $_cont, $match );

                 
$__res = htmlspecialchars($this->start_tag) .' :: '. htmlspecialchars($match[1]);
              }
          }

          if(
$__res)
          {
             
$_res = $__res;
          }
          else
          {
             
$_res = $this->DefineError[4];
          }
        }
        else
        {
             
$_res = $this->DefineError[2];
        }

      return
$_res;
    }

   
// for return the contents you file ..
   
function LoadPage()
   {
         if(
$this->path == "")
         {
           
$this->conts = $this->DefineError[2];
         }
         else
         {
           
$open_file = @fopen($this->path, 'r') or die ($this->DefineError[3]);

            while( !
feof ($open_file) )
            {
               
$buf = trim( fgets( $open_file, 4096 ) );
               
$this->conts .= $buf;
            }

            @
fclose($open_file);

         }

      return
$this->conts;
    }

   
// for check ( Start Tag == End Tag)
   
function check($st,$et)
    {
         
$check_start1 = preg_replace("/<(.+)>/U","\\1",$st);
         
$check_start = explode(" ",$check_start1);
         
$check_end   = preg_replace("/<(.+)>/U","\\1",$et);
         
$check_end = str_replace ('\\/','',$check_end);

         if(
is_array($check_start))
         {
           
$get_tag_name = $check_start[0];
         }
         else
         {
           
$get_tag_name = $check_start1;
         }


         if(
$get_tag_name == $check_end)
         {
             return
true;
         }
         else
         {
             return
false;
         }
    }

}

// End Class :)
?>




index.php
<?php

/***************************************************************************
============================================================================
| @ Script Name             : Get Tag Value
| @ Version                 : 1.0
| @ Description             : Get The Tag Value .
| @ All rights reserved to  : NaiF PHP
| @ Created In              : 09-07-2007
| @ Support                 : wald_al_dala@hotmail.com
============================================================================
****************************************************************************/

echo (" <html dir=\"ltr\">\n<title> Get Tag Value </title> ");


include
"GTV.class.php";

//======================================
// Note :
// write Start Tag like this : <tag>
//   =    =     =   =    =   : <\/tag>
// example (1) :
//======================================

$ob = new GTV(
             
"test.php",
              array(
"<title>","<h3>","<font color=\"red\">"),
              array(
"<\/title>","<\/h3>","<\/font>")
              );

echo
"<pre>";
print_r ($ob->tag_value);

//======================================
// example (2) :
//======================================

echo "<br><hr><br>";


$ob = new GTV(
             
"test.php",
             
"<head>",
             
"<\/head>"
             
);

echo
"<pre>";
print_r ($ob->tag_value);



//======================================
// example (3) :
//======================================

echo "<br><hr><br>";;


$ob = new GTV(
             
"test.php",
             
"<title>",
             
"<\/title>"
             
);

echo
"<pre>";
echo
$ob->tag_value;


//======================================
// your can using this class to do : Ex 4
// example (4) :
//======================================

echo "<br><hr><br>";;


$ob = new GTV(
             
$_SERVER['HTTP_REFERER'],
             
"<title>",
             
"<\/title>"
             
);

echo
"<pre>";
$title_reff = $ob->tag_value;
// remove _tag_
$Title = explode("::",$title_reff);

echo
" Your come from site : <a href=\"".$_SERVER['HTTP_REFERER']."\">",$Title[1] ,"</a>";

echo
"</pre>";
// End Example


echo "<br><br><br>",highlight_file(__FILE__,true);

?>




test.php
<html>

<head>
  <title> Test Page ( class GTV )</title>
</head>

<body>

<h2> Hello Every one :) </h2>

<br>

<font color="red"><h3> Class : GTV </h3></font>


</body>

</html>





FormChecker Package - validate any data via classes and patterns.
Categories : PHP, Form Processing, PHP Classes, Regexps
Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface. This version obsoletes version 1.0a
Categories : HTML, PHP, PHP Classes, Regexps
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
Parsing Simple Template Files and Data
Categories : PHP, PHP Classes, Templates, Regexps
Banknote Validation - A PHP class that provides several methods to quickly validate banknote serial numbers of the following currencies: AUD, CAD, CHF, CNY, EUR, GBP, JPY, USD.
Categories : PHP, PHP Classes, Data Validation, Regexps
EAvalidator - This class can be used to validate an e-mail address by checking its domain.
Categories : PHP, PHP Classes, Email, Regexps
Password reminder
Categories : PHP, PHP Classes, Databases, MySQL, Mail
How to strip non-alpha characters from a string
Categories : Regexps, PHP
Form Elements Class
Categories : PHP, PHP Classes, Form Processing
Get the AppStore Ranking for any iPhone App
Categories : PHP, Web Services, Regexps
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
Filter - A simple class that lets you use multiple functions to create custom filters.
Categories : PHP, PHP Classes, Strings
DbObject - A PHP wrapper for working with various databases
Categories : Databases, PHP, PHP Classes
The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view.
Categories : PHP, PHP Classes, Java Script, AJAX, Databases
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs