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 : Parsing html tags with php. Get an array from this function
Categories : PHP, HTML and PHP, Arrays, Tag Extractors Update Picture
Carlos Jordao
Date : Feb 14th 2001
Grade : 3 of 5 (graded 12 times)
Viewed : 80478
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Carlos Jordao
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
/*
* parseHtml.php
* Author: Carlos Costa Jordao
* Email: carlosjordao@yahoo.com
*
* My notation of variables:
* i_ = integer, ex: i_count
* a_ = array, a_html
* b_ = boolean,
* s_ = string
*
* What it does:
* - parses a html string and get the tags
* - exceptions: html tags like <br> <hr> </a>, etc
* - At the end, the array will look like this:
* ["IMG"][0]["SRC"] = "xxx"
* ["IMG"][1]["SRC"] = "xxx"
* ["IMG"][1]["ALT"] = "xxx"
* ["A"][0]["HREF"] = "xxx"
*
*/
function parseHtml( $s_str )
{
$i_indicatorL = 0;
$i_indicatorR = 0;
$s_tagOption = "";
$i_arrayCounter = 0;
$a_html = array();
// Search for a tag in string
while( is_int(($i_indicatorL=strpos($s_str,"<",$i_indicatorR))) ) {
// Get everything into tag...
$i_indicatorL++;
$i_indicatorR = strpos($s_str,">", $i_indicatorL);
$s_temp = substr($s_str, $i_indicatorL, ($i_indicatorR-$i_indicatorL) );
$a_tag = explode( ' ', $s_temp );
// Here we get the tag's name
list( ,$s_tagName,, ) = each($a_tag);
$s_tagName = strtoupper($s_tagName);
// Well, I am not interesting in <br>, </font> or anything else like that...
// So, this is false for tags without options.
$b_boolOptions = is_array(($s_tagOption=each($a_tag))) && $s_tagOption[1];
if( $b_boolOptions ) {
// Without this, we will mess up the array
$i_arrayCounter = (int)count($a_html[$s_tagName]);
// get the tag options, like src="htt://". Here, s_tagTokOption is 'src'
and s_tagTokValue is '"http://"'

do {
$s_tagTokOption = strtoupper(strtok($s_tagOption[1], "="));
$s_tagTokValue = trim(strtok("="));
$a_html[$s_tagName][$i_arrayCounter][$s_tagTokOption] =
$s_tagTokValue;
$b_boolOptions = is_array(($s_tagOption=each($a_tag))) &&
$s_tagOption[1];
} while( $b_boolOptions );
}
}
return $a_html;
}

?>



Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
navbar.php3 - Dynamic hyperlinked navigation bars
Categories : HTML and PHP, Arrays, PHP, Complete Programs
Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays
How to pass an array from one PHP Script to another via an HTML form
Categories : PHP, HTML and PHP, Arrays
Print out array key => value in colored HTML
Categories : PHP, Arrays, HTML and PHP
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
Parse string to find sub-string between two arbitrary strings
Categories : PHP, Strings, HTML and PHP, Arrays
Parse a HTML-document for a certain tag and display its content and attributes.
Categories : HTML and PHP, PHP, Tag Extractors
PHP based HTML rabbing Tools
Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides
Simple script to passing persistent and growing array between recalls of one page (manipulate little stack).
Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables
CSS style switcher
Categories : PHP, CSS, HTML and PHP, Arrays, Sessions
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
Sql Builder
Categories : PHP, HTML and PHP, Databases, General SQL, Form Processing
PHPDRAW, the php wannabe Photoshop ;-)
Categories : PHP, PHP Classes, GD image library, Arrays
 jefferis peterson wrote :1189
Fails on first line Parse error: parse error, unexpected T_STRING
            function parseHtml( $s_str )