Can anybody help me with this problem:
How can I echo a string that contain <? and <?php?
For example,
$str="test <? and <?php echo";
echo $str;
What I get is: test instead of: test <? and <?php echo
Thanks. 7 5174
On 20 Jul 2004 07:15:13 -0700, haoren hath writ: Can anybody help me with this problem:
How can I echo a string that contain <? and <?php?
For example,
$str="test <? and <?php echo";
$str="test <? and <?php echo";
echo $str;
What I get is: test instead of: test <? and <?php echo
Thanks.
.oO(haoren) How can I echo a string that contain <? and <?php?
For example,
$str="test <? and <?php echo"; echo $str;
echo htmlspecialchar s($str); http://www.php.net/htmlspecialchars
Micha
haoren wrote: Can anybody help me with this problem:
How can I echo a string that contain <? and <?php?
For example,
$str="test <? and <?php echo"; echo $str;
What I get is: test instead of: test <? and <?php echo
Thanks.
Just use single quotes:
<?php
$string = 'test <? and <?php echo';
echo $string;
?>
On Tue, 20 Jul 2004 07:15:13 -0700, haoren wrote: Can anybody help me with this problem:
How can I echo a string that contain <? and <?php?
For example,
$str="test <? and <?php echo"; echo $str;
What I get is: test instead of: test <? and <?php echo
Thanks.
You should _never_ be echoing a < or > char to the browser, this should
_always_ be < or >.
echo htmlentities($s tr);
would work in your instance for example.
Regards,
Ian
--
Ian.H
digiServ Network
London, UK http://digiserv.net/
On Tue, 20 Jul 2004 15:24:59 GMT
"Ian.H" <ia*@WINDOZEdig iserv.net> wrote: On Tue, 20 Jul 2004 07:15:13 -0700, haoren wrote:
[SNIP] You should _never_ be echoing a < or > char to the browser, this should_always_ be < or >.
That's interesting... How do you output HTML from PHP then? :-p
What he's trying to say is that if you want a < or a > to show up in
your browser, you should use < and >, since < and > are the chars
used to delimit HTML tags, so the browser will think that the < or > you
just echo'ed out is part of the HTML.
So, again... If you want < and > to print in e.g. a text, use 'echo
"< and >";'
Madsen
--
Anders K. Madsen --- http://lillesvin.linux.dk
"There are 10 types of people in the world.
Those who understand binary - and those who don't."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA/UhClNHJe/JASHcRAuwPAJ4o6 pf0fZ5cP6lTfzCT x1oPTlo0lACeJNW b
0vAnrn3qWfjMMuY s/mS4hes=
=pyP0
-----END PGP SIGNATURE-----
On Tue, 20 Jul 2004 18:28:47 +0200, Anders K. Madsen wrote: On Tue, 20 Jul 2004 15:24:59 GMT "Ian.H" <ia*@WINDOZEdig iserv.net> wrote:
On Tue, 20 Jul 2004 07:15:13 -0700, haoren wrote: [SNIP] You should _never_ be echoing a < or > char to the browser, this should_always_ be < or >.
That's interesting... How do you output HTML from PHP then? :-p
What he's trying to say is that if you want a < or a > to show up in your browser, you should use < and >, since < and > are the chars used to delimit HTML tags, so the browser will think that the < or > you just echo'ed out is part of the HTML. So, again... If you want < and > to print in e.g. a text, use 'echo "< and >";'
Madsen
lol oops =)
Yup, that pretty much sums it up.. I was referring to if you wanted to
display < or > chars, they should _always_ be entities rather than their
actual chars.
FWIW.. I rarely output HTML from PHP... gotta love Smarty ;)
Regards,
Ian
--
Ian.H
digiServ Network
London, UK http://digiserv.net/
I should have put the question in the context. In fact, the string is
received from user's input to the form of a browser. Thus, echo
htmlspecialchar s($str); can solve the problem.
Thanks Michael and all you guys.
haoren
Michael Fesser <ne*****@gmx.ne t> wrote in message news:<9t******* *************** **********@4ax. com>... .oO(haoren)
How can I echo a string that contain <? and <?php?
For example,
$str="test <? and <?php echo"; echo $str;
echo htmlspecialchar s($str);
http://www.php.net/htmlspecialchars
Micha This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: The Plankmeister |
last post by:
Hi...
I seem to remember reading somewhere about the proper way of doing this sort
of thing in the middle of some html, for example:
<a href="<?= $some_url_or_other ?>">Click this!</a>
What is the most proper way of doing such? Would it be to do the full
monty?:
|
by: lawrence |
last post by:
In the following loop, at the end, the method debugNotes() is printing
out some notes for me to read, so I can figure out what is going on in
my script. Where I try to print out the value of the variable $noFile,
it is print "1" instead of "true". Why does it do this?
The loop is failing to run a second time, for reasons I can not
fathom. debugNotes tells me that the count of $dirArray is 10, and the
file hasn't been found yet, so I...
|
by: Jonny T |
last post by:
hi,
i want to echo the string '<?php' in a php script like :
echo "<?php";
but when i try nothing gets displayed ...
if I use
echo "<\?php";
|
by: J Trost |
last post by:
I was wondering if anyone knows if it is possible to do basic string
replacement using XSLT even though the strings being replaced may
contain "<" and ">". Here is my problem:
I need to be able to convert XML like this:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_03" class="java.beans.XMLDecoder">
<object class="javax.swing.JButton">
<string>Hello, world</string>
|
by: Arne Schirmacher |
last post by:
I want to display a MySQL database field that can contain HTML markup.
If I use <esql:get-string> then I get all of the database field, but
all tags are escaped which is not what I want. If I use <esql:get-xml>
the tags are not escaped, but only the first part of the database
field is displayed.
The content of the database field is:
"<h1>Title</h1><h2>Subtitle</h2>"
| |
by: Michael G |
last post by:
Some of the online docs say that you can use
echo <<<END
all sorts of text and statements...
END;
but if the following produces a parse error at line 14 which is the closing
|
by: vunet.us |
last post by:
Hello,
I use XMLHTTP to get an HTML of another page. Then, I need to cut some
middle part of that HTML string but I have problems doing it (see note
in caps below). The error I have generated at response.write (because
it does not split) is:
Microsoft VBScript runtime error '800a0009'
Subscript out of range: ''
/get_item.asp, line 55
|
by: pnsreee |
last post by:
Hi All,
I have the following code.
The array @sub_data will contain integers or a string"NO". I have to validate if the array contain integer. If it contain "NO" then no need to validate.
for ($i=1;$i<10;$i++)
{
Tie::CheckVariables->on_error(sub{print "ERROR!"});
tie my $data,'Tie::CheckVariables','integer';
|
by: John Nagle |
last post by:
I have XML replies in a DOM which contain entity escapes,
like "&". What's the proper way to replace them with
the ordinary characters? Preferably something that will work in
most browsers?
I know about ".innerText", but that's not portable; some
browsers convert escapes when reading from innerText and some
don't.
John Nagle
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |