Re: Help?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, March 23, 2006 1:50 pm, Clinton, Rochelle A wrote:
> I am fairly new to PHP and am having an (SILLY) issue that I cannot
> seem
> to resolve:
>
> I am pulling data from an html file and some of the lines of text that
> I
> need start with "</a>".

Show us an actual line, copy/paste, to be sure we are working on the
right thing...

> I cannot seem to get rid of that tag!!!
>
> I have tried:
>
> *	str_replace("<\a>", "", $line)

You need to do:
$line = str_replace("</a>", "", $line);

Otherwise, you calculate the answer you want, and throw it away.

> *	preg_replace('/<\/a>/', '', $line)  and various other attempts

Technically, you'd want:
'/<\\/a>/'

As \ is a special character inside '' marks, and PHP needs \\ to
represent \

It "works" because only \\ and \' are special inside '', so PHP
"figures out" \a as just \a

But it helps one understand strings better to be pedantic and use \\
inside '' to mean \

Again, it would seem you've left out the crucial step of storing the
result you want:

$line = preg_replace(..., $line);

> at creating the appropriate regex for <\a>

Is it really </a> or <\a>?

Because / and \ are not the same, despite the number of people, even
professional radio announcers, who insist on calling / 'backslash'

/ slash
\ backslash

You'd think they'd do their homework, eh?  Oh well.

I think the browsers have mainly gotten to the point where they just
try switching things around from \ to / if you goof anyway...

Must be frustrating to write a web browser...  Almost as frustrating
as trying to code HTML to one. :-)

> *	$line = htmlspecialchars($line)
>
> str_replace("&lt;/a&gt;", "", $line)

This would, in theory, "work" IF you had '$line =' in front of the
str_replace (again), but adds a pointless extra step to convert to
HTML Entities before ripping out characters you don't want in the
first place.

> *	And obviously strip_tags is not working for me either!

$line = strip_tags($line);

It seems like your primary difficulty in all this is in understanding
that MOST (if not all) PHP functions on strings will return the new
value, rather than destructively modify the input string.

It is possible, in some versions of PHP, to specifically craft
functions that will ALTER the input string.  But that's generally done
for performance reasons, and only in very specialized situations in
highly-optimized application code.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux