By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,432 Members | 795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,432 IT Pros & Developers. It's quick & easy.

How do I escape angle brackets?

P: n/a
I have a line like this in some PHP code on my Web page:

$callthis =~ s/<[^>]*>//g;

When the page runs, I get this error:

Parse error: parse error, unexpected '<' in /Feedback.php on line 145

So I presume I must escape angle brackets somehow in the regular
expression. How do I do it? I tried putting a backslash in front of
each angle bracket, but that doesn't seem to work (same error).

The purpose of the statement is to remove HTML tags from the string.

--
Transpose hotmail and mxsmanic in my e-mail address to reach me directly.
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

Mxsmanic wrote:
I have a line like this in some PHP code on my Web page:

$callthis =~ s/<[^>]*>//g;

When the page runs, I get this error:

Parse error: parse error, unexpected '<' in /Feedback.php on line 145


That doesn't look like any PHP code that I know.
Use the function strip_tags() to strip HTML from strings.

Ken

Jul 17 '05 #2

P: n/a
Mxsmanic wrote:
I have a line like this in some PHP code on my Web page:

$callthis =~ s/<[^>]*>//g;
Looks like Perl to me.
When the page runs, I get this error:

Parse error: parse error, unexpected '<' in /Feedback.php on line 145

So I presume I must escape angle brackets somehow in the regular
expression. How do I do it?
With a \ but I doubt that's the problem.
I tried putting a backslash in front of
each angle bracket, but that doesn't seem to work (same error).
That's because it's not PHP.

Try this: $callthis = preg_replace("/<[^>]*>/", "", $callthis);
The purpose of the statement is to remove HTML tags from the string.


Try using the strip_tags() function: http://www.php.net/strip_tags

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #3

P: n/a
Ken Robinson writes:
That doesn't look like any PHP code that I know.
Doesn't PHP support substitution with regular expressions?

I'm always getting confused between Perl and PHP.
Use the function strip_tags() to strip HTML from strings.


Thanks, I'll do that instead.

--
Transpose hotmail and mxsmanic in my e-mail address to reach me directly.
Jul 17 '05 #4

P: n/a
Chris Hope writes:
Looks like Perl to me.
It would work in Perl. Doesn't PHP support regular expressions? I can
never remember which language supports what.
Try using the strip_tags() function: http://www.php.net/strip_tags


Done, and it works. Thanks.

--
Transpose hotmail and mxsmanic in my e-mail address to reach me directly.
Jul 17 '05 #5

P: n/a
Mxsmanic wrote:
Chris Hope writes:
Looks like Perl to me.


It would work in Perl. Doesn't PHP support regular expressions? I
can never remember which language supports what.


Yes, PHP does support regular expressions. I gave you the code for it.
Here it is again:

$callthis = preg_replace("/<[^>]*>/", "", $callthis);

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #6

P: n/a
n
Mxsmanic wrote:
Ken Robinson writes:

That doesn't look like any PHP code that I know.

Doesn't PHP support substitution with regular expressions?

I'm always getting confused between Perl and PHP.

Use the function strip_tags() to strip HTML from strings.

Thanks, I'll do that instead.


I just wanted to add that the code looks like perl.

T
Jul 17 '05 #7

P: n/a

Mxsmanic wrote:
I have a line like this in some PHP code on my Web page:

$callthis =~ s/<[^>]*>//g;

When the page runs, I get this error:

Parse error: parse error, unexpected '<' in /Feedback.php on line 145

this is because you've tried to use a PERL expression. in PHP, you'd
do something more like this:

$callthis = preg_replace("\<[^\>]*\>","",$callthis);

but as another poster mentioned, PHP already has a function for the
purpose you specified.

hope that clears things up for you.

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.