[SOLVED] Need help with regualr expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raymedia
Forum Commoner
Posts: 27
Joined: Thu Oct 09, 2003 6:36 am
Location: Melbourne, Australia

[SOLVED] Need help with regualr expression

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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> ) '
User avatar
raymedia
Forum Commoner
Posts: 27
Joined: Thu Oct 09, 2003 6:36 am
Location: Melbourne, Australia

Post 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;
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
raymedia
Forum Commoner
Posts: 27
Joined: Thu Oct 09, 2003 6:36 am
Location: Melbourne, Australia

Post by raymedia »

Great..its working now... thanks for your help.. have a great day
Post Reply