WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 5 times)
Viewed : 7364
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  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
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
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
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
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
Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
Get the AppStore Ranking for any iPhone App
Categories : PHP, Web Services, 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)
how to check if a string contains a letter from a different language?
Categories : PHP, Regexps, Languages
php table decoder used to convert an html table to individual tokens through regular expressions
Categories : PHP, Regexps, HTML and PHP
Show Source with Line Numbers
Categories : PHP, Regexps, Filesystem