473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How do I escape angle brackets?

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
7 6658

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
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
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
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: BTnews | last post by:
Hi, Can anyone here point me at a definitive guide or tutorial about using escape characters when building SQL queries from user entered data? I'm especially interested in info on this in regard...
1
by: bartek | last post by:
Hi, I'm aware that both quoted and angle-bracketed strings in an #include directive result in implementation-defined file lookup, differing in the fact that #include "foo.h" first checks...
2
by: Matthew Wieder | last post by:
In my previous post, I asked about a routine which prepares a string for an XPath query by taking care of escape characters. Unable to find a list, I'm now wondering assumign I enclose the...
2
by: DotNetGruven | last post by:
We have a web service that returns a string which happens to be well formed XML. The client sees the string ok, except the angle brackets are HTML encoded ( &gt and &lt ). Is this expected...
2
by: Kenneth Porter | last post by:
If you email your users links and wrap the links in angle brackets, beware users using Yahoo Mail. It includes the trailing angle bracket in the link, preventing it from working. (This was...
2
by: Peter | last post by:
Hi, I was wondering, can anyone tell me what statements in angle brackets are for in VB? For example, the default <System.Diagnostics.DebuggerStepThrough()thing that the IDE puts before the...
4
by: Nunzio | last post by:
I am trying to build an email address in PHP code using v5.1.2. All works well until I try to surround the email address with angle brackets. Every method I try causes the email address to...
1
by: pronerd | last post by:
Hi, I was wondering if any one knows of an easy way to add escape characters to an existing string in a BASH script. I have a BASH script that is failing when a string is passed with brackets...
4
by: Keith Hughitt | last post by:
Hi all, I am using someone else's script which expects input in the form of: ./script.py <arg1arg2 I was wondering if the angle-brackets here have a special meaning? It seems like they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.