Page 1 of 1

[SOLVED] Need help with regualr expression

Posted: Wed Oct 06, 2004 6:13 am
by raymedia
hi guys,
this is my code

Code: Select all

$str = '<TD class="clsNormal">(03) 9391 4572.</TD>';
$strNoHTML= preg_split('((>)|(<))', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
print_r($strNoHTML);

//display: 'Array ( &#1111;0] => <TD class="clsNormal">(03) 9391 4572.</TD> ) '
So, why its not removing the html tags? Any help will be great

Posted: Wed Oct 06, 2004 6:21 am
by feyd
you don't have a beginning and ending delimiter:

Code: Select all

$str = '<TD class="clsNormal">(03) 9391 4572.</TD>';
$strNoHTML= preg_split('#(>|<)#', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
print_r($strNoHTML);

//display: 'Array ( [0] => <TD class="clsNormal">(03) 9391 4572.</TD> ) '

Posted: Wed Oct 06, 2004 6:34 am
by raymedia
thanks feyd..but its not working. this is my full code

Code: Select all

function getSchoolInfo()&#123;
		$lines = file('http://www.eduweb.vic.gov.au/SchoolsOnline/Details.asp?LocationID=01493101');
		
		$schoolPhone = htmlspecialchars($lines&#1111;81]);
		print_r(remHTML($schoolPhone));
	&#125;

	function remHTML($str)&#123;
		$strNoHTML= preg_split('#(>|<)#', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
		return $strNoHTML;
	&#125;

Posted: Wed Oct 06, 2004 7:09 am
by twigletmac
It would be a good idea to do htmlspecialchars() after the regex - remember that < and > will get converted to their entity equivelants using that function...

(look at the source of your generated page)

Mac

Posted: Wed Oct 06, 2004 7:12 am
by raymedia
Great..its working now... thanks for your help.. have a great day