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
PHP Web Logs (BLogs)
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
Submit Site
Forex Trading Online forex trading platform

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 : 2219
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>





YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
Parsing Simple Template Files and Data
Categories : PHP, PHP Classes, Templates, Regexps
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
very simple ftp class
Categories : PHP, PHP Classes, FTP
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
A Timing Class
Categories : PHP, PHP Classes, Date Time
The class to check load time of your script VERY usefull for relatively slow applications, but not only..
Categories : PHP, PHP Classes, Debugging
Create HTML forms dynamicly using Javascript & PHP
Categories : PHP, PHP Classes, Java Script
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
This script is a contact form between users of a website (kinda like the PM function on the forums)
Categories : PHP, Databases, MySQL, Regexps
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
Simple way to replace a variable value in a .conf (.ini) file using a webbrowser - the first stage of a complete universal configuration editor
Categories : PHP, Regexps, Code Editors, Filesystem
ereg -- Regular expression match
Categories : PHP, PHP Functions, Regexps