Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I escape angle brackets in php?

Posted on 2011-05-10
4
Medium Priority
?
480 Views
Last Modified: 2012-05-11
How do I escape angle brackets in php?
0
Comment
Question by:vibrantc
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 1000 total points
ID: 35728699
htmlentities():

$str="<p>hello</p>";
echo htmlentities($str,ENT_QUOTES);

http://us2.php.net/manual/en/function.htmlentities.php
0
 
LVL 4

Assisted Solution

by:secondv
secondv earned 1000 total points
ID: 35743206
If by angle brackets you do mean < & >, I would not recommend htmlentities, it's going to convert more than that.

You can do this:

<?php

$string = '<p>Hello World.</p>';
$string = str_replace(array('<', '>'), array('&lt;', '&gt;'), $string);
echo $string;

?>

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 37330035
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question