473,397 Members | 2,056 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,397 software developers and data experts.

HTML is trunctating PHP text

Hello Folks

Does anybody know why the text box on this page is trunctating $test to
Mary?

Thanks

Nick

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-
1252">
<title>New Page 1</title>
</head>

<body>

<?php
$test = "Mary had a little lamb";
?>

<form method="POST" action="edit_user.php"
<p><input type="text" name="T1" size="30" value=<?php echo $test;
?> tabindex="1"><input type="submit" value="Submit" name="B1"><input
type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>
Jul 17 '05 #1
3 1323
Busy <bu********@blueyonder.co.uk> wrote:
Does anybody know why the text box on this page is trunctating $test
to Mary? .... $test = "Mary had a little lamb"; .... <input type="text" name="T1" value=<?php echo $test;?>>


Take a look at the source (the first place you should look to see what
PHP is actually doing) and you will see it's all there as:
<input type="text" name="T1" value=Mary had a little lamb>

See the html specs on attributes (that is what value is):
http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.2

To make a long boring spec short:

The value should be surrounded by quotes if it contains whitespaces,
the quotes used to delimit should be escaped within the value.

eg:
<input type="text" name="T1" value="<?php echo $test;?>">
or
<input type="text" name="T1" value='<?php echo $test;?>'>

would be fine in this case, but will fail if there are quotes in $test:

$test = "The lamb will soon be Mary's little \"ham\"";

will break either quoting style unless escaped with:
<input type="text" name="T1" value='<?php echo htmlspecialchars($test,ENT_QUOTES);?>'>
Jul 17 '05 #2
Busy (bu********@blueyonder.co.uk) wrote:
: Hello Folks

: Does anybody know why the text box on this page is trunctating $test to
: Mary?

: Thanks

: Nick

: <html>

: <head>
: <meta http-equiv="Content-Type" content="text/html; charset=windows-
: 1252">
: <title>New Page 1</title>
: </head>

: <body>

: <?php
: $test = "Mary had a little lamb";
: ?>

: <form method="POST" action="edit_user.php"
: <p><input type="text" name="T1" size="30" value=<?php echo $test;
^^^^^^^^^^^^^^

Html requires

value="a quote string goes here"

Instead You are generating

value=Mary had a little lamb

which is bad html, and sets the value to the single word "Mary"

So you want

value="<?php echo $test;?>"
^ ^

(note quotes) __However__ even then, think about what happens if $test
contains

$test='ha ha"> </form>';

That will mess up your html for sure. So in general you must also escape
the data before you put it into html. There are functions to do that, I
don't recall the names of the php functions you use but the ref manual
lists them all.
--

This space not for rent.
Jul 17 '05 #3
.oO(Malcolm Dew-Jones)
So in general you must also escape
the data before you put it into html. There are functions to do that, I
don't recall the names of the php functions you use but the ref manual
lists them all.


htmlspecialchars()

Micha
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
4
by: frogman042 | last post by:
My daughter is playing around trying to learn JavaScript and she wrote a small program that prints out a message in increasing and decreasing font size and color changes. She is using document...
17
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
1
by: since | last post by:
I figured I would post my solution to the following. Resizable column tables. Search and replace values in a table. (IE only) Scrollable tables. Sortable tables. It is based on a lot...
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
2
by: sateeshchandrasanga | last post by:
Hi All, My HTML code is working fine in Firefox.But its not displaying any thing in IE.Can you help me in this problem.And in Google crown its displaying but not properly. ...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.