Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg replace patterns inside tags

Status
Not open for further replies.

pushyr

Programmer
Jul 2, 2007
159
GB
just a quick preg replace problem

i have title tags that look like this....

Code:
<title>

	title of my page

</title>

i would like to change them to this...

Code:
<title>title of my page</title>

what would be the correct way to strip out any spaces and tabs before and after the text, plus any carriage returns inside the tags?

 
Code:
<?php
function parseTitle($html){
	$pattern = '/<title>(.*?)</title>/imsxe';
	return preg_replace(	
					$pattern, 
             		"'<title>'.trim('\\').'</title>'",
					$html); 
}
?>
 
hey jpadie, i'm gettinh this error message...

Warning: preg_replace() [function.preg-replace]: Unknown modifier 't' in
 
oops
Code:
$pattern = '/<title>(.*?)<[red]\[red]/title>/imsxe';
 
still getting the same error

what does the [red] mean?
 
it was supposed to be emphasis!

Code:
$pattern = '/<title>(.*?)<[red]\[/red]/title>/imsxe'
 
for some reason i just keep getting an error...

Code:
function parseTitle($content01){
    $pattern = '/<title>(.*?)<\/title>/imsxe';
    return preg_replace($pattern, "'<title>'.trim('\\').'</title>'", $content01);
}


$content = parseTitle($content01);


echo '<xmp>'.$content.'</xmp>';
 
i must have been very tired yesterday.

this should look as follows
Code:
return preg_replace($pattern, "'<title>'.trim('\\[red]1[/red]').'</title>'", $content01);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top