RE: [PHP-WIN] Read random text between known tags from a file

From: Date: Thu, 26 Oct 2000 15:40:18 +0000
Subject: RE: [PHP-WIN] Read random text between known tags from a file
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-3520@lists.php.net to get a copy of this message
I've made some class for handling a tag ... not some short stuff ;) <-------- snip tag.class.php -------------> <?PHP class cTag { var $name; var $parameter; var $content; var $length; function parse($string) { $target=""; $open=false; for($i=0;$i<strlen($string);$i++) { if ((substr($string,$i,1)=="\"")||(substr($string,$i,1)=="'")) { $open=true-$open; } if ((substr($string,$i,1)==" ")&&$open) { $target.="&nbsp;"; } else $target.=substr($string,$i,1); } $string=$target; $begin=strpos($string,"<"); $end=strpos($string,">"); $tagcontent=substr($string,$begin+1,$end-$begin-1); if (strpos($tagcontent," ")) { $paramcontent=substr($tagcontent,strpos($tagcontent," ")+1); //*** $param=explode(" ",$paramcontent); $i=0; reset($param); while(list($k,$v)=each($param)) { $t=explode("=",$v); $t[1]=trim(strtr($t[1],"\"'"," ")); $p[$t[0]]=$t[1]; } $this->parameter=$p; // Parameters of Tag $this->name=substr($tagcontent,0,strpos($tagcontent," ")); } else { $this->name=$tagcontent; // No Parameters } if (strpos($string,"</".$this->name.">")) { // If End-Tag availible $this->content=substr($string,$end+1,strpos($string,"</".$this->name.">")-1- $end); $end=strpos($string,"</".$this->name.">")+2+strlen($this->name); } $this->lenght=$end-$start+1; } function out() { $r=""; $r.="<$this->name"; if (is_array($this->parameter)) { // Parameter reset($this->parameter); while(list($k,$v)=each($this->parameter)) { $r.=" $k=\"$v\""; } } if ($this->content!="") { $r.=">$this->content</$this->name>"; } else { $r.=">"; } return $r; } } $tag=new cTag; $tag->parse("<META NAME=\"stuff\" CONTENT=\"blah\">"); echo "tag-name: ".$tag->name."<br>"; echo "tag-parameters: ".count($tag->parameter)."<br>"; echo "tag-parameter[\"NAME\"]: ".$tag->parameter["NAME"]."<br>"; ?> <-----------------------------------------> CodeDuck > -----Original Message----- > From: Yoeri De Bruyn [mailto:yoeri_de_bruyn@multicap.be] > Sent: Thursday, October 26, 2000 5:04 PM > To: php Windows > Subject: [PHP-WIN] Read random text between known tags from a file > > > Hi phpeers! > > I need to retrieve the text between [<META NAME="description" CONTENT=] > and [ >]. > Any body an idea on how to achieve this? > Should it work with "ereg"? If so, how exactly? > > Any tip, trick or even example will be very appreciated! > > kr, > Yoeri. > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.windows (#3520) next »