Hello I have just made this regex and tested using this tool
http://gskinner.com/RegExr/

I am trying to match (x)html, xml & html4.0 in group so that I may return

$matches[0] // the full tag
$matches[1] // the start tag including any attribs etc
$matches[2] // the tag name
$matches[3] // the innerHTML or data inside the tag "excluding HTML" (needs to be optional)
$matches[4] // an optional endtag (needs to be optional)

this is my current regex and I think it's okay hehe
CODE([\w].+)?(</[a-zA-Z0-9]+?>)[/CODE]

im using it with

preg_match_all("/(<([\w]+)[^>]*>)([\w].+)?(</[a-zA-Z0-9]+?>)/", $htmldoc, $matches, PREG_SET_ORDER);

PHP returns this error

Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '[' in /var/www/PgEditor/class.php on line 18

plz help its doin my box in

    You need to escape the / in the middle and add s modifier if newlines are between the tags.

    preg_match_all("/(<([\w]+)[>]*>)([\w].+)?(<\/[a-zA-Z0-9]+?>)/s", $htmldoc, $matches, PREG_SET_ORDER);

      unfortunately that is not returning any data now lol, thanks alot though, I think for the system i want to implement regex is insufficient anyway, thanks loads.

        Dont worry I am rewriting the tag parser using xml to array heres what I have so far

        <?php
            echo"hello world!";
        ?>
        

        pmsl nah only joking I have this

        <?php
        	class tagparse
        	{
        		private $data;
        		private $vals;
        		function tagparse($DATA, $WHITE=1)
        		{
        			$index = array();
        			$this->data = trim($DATA);
        			$this->data = str_replace("&nbsp;", "[tagparse::space]", $this->data); // fix for &nbsp;
        			$this->data = preg_replace("/(<(\w+).*?>)(<\/\\2>)/", "\\1[tagparse::empty]\\3", $this->data); // fix for empty tags that do not use ommittag
        			$this->vals = array();
        			$parser = xml_parser_create();
        			xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        			xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
        			if ( !xml_parse_into_struct($parser, $this->data, $this->vals, $index) )
        				die("XML error: ".xml_error_string(xml_get_error_code($parser))." at line ".xml_get_current_line_number($parser));
        			xml_parser_free($parser);
        			/*
        			 * The code below is all for using of &nbsp; and empty tags that do not use ommittag
        			 */
        			$this->data = str_replace("[tagparse::space]", "&nbsp;", $this->data);
        			$this->data = str_replace("[tagparse::empty]", "", $this->data);
        			for($i = 0;$i<count($this->vals);$i++)
        			{
        				if(isset($this->vals[$i]['value']))
        				{
        					if(strstr($this->vals[$i]['value'], "[tagparse::space]") !== false)
        						$this->vals[$i]['value'] = str_replace ("[tagparse::space]", "&nbsp;", $this->vals[$i]['value']);
        					if(strstr($this->vals[$i]['value'], "[tagparse::empty]") !== false)
        						$this->vals[$i]['value'] = str_replace ("[tagparse::empty]", "", $this->vals[$i]['value']);
        				}
        			}
        		}
        		function outputString()
        		{
        			$output = "";
        			for($i = 0;$i<count($this->vals);$i++)
        			{
        				//output whole array into formatted file
        				$indent = $attribs = "";
        				if($this->vals[$i]['level'] > 1)
        					$indent = str_repeat("\t", $this->vals[$i]['level']-1);
        				if(isset($this->vals[$i]['attributes']))
        				{
        					foreach($this->vals[$i]['attributes'] as $key=>$val)
        					{
        						$attribs.= " ".$key."=\"".$val."\"";
        					}
        				}
        				switch($this->vals[$i]['type'])
        				{
        					case "open":
        						$output .= $indent."<".$this->vals[$i]['tag'].$attribs.">\r\n";
        					break;
        					case "complete":
        						$ommittag = "";
        						if(!isset($this->vals[$i]['value']))
        							$output .= $indent."<".$this->vals[$i]['tag'].$attribs." />"."\r\n";
        						else
        							$output .= $indent."<".$this->vals[$i]['tag'].$attribs.">".$this->vals[$i]['value']."</".$this->vals[$i]['tag'].">"."\r\n";
        					break;
        					case "close":
        						$output .= $indent."</".$this->vals[$i]['tag'].">\r\n";
        					break;
        				}
        			}
        			return $output;
        		}
        		function outputArr()
        		{
        			return str_replace("1", "", print_r($this->vals));
        		}
        	}
        
        ?>
        

        any ideas for this class??? im already adding functionality to it

          Write a Reply...