472,783 Members | 940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to store HTML code (with " ", ' ') inside a variable in php script?

Hello to everyone,

Assuming i have this simple script :

<?PHP

//Opening tag ='
$html_header='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
'; // Closing tag ='

echo $html_header;

?>

If the opening & closing tags are both ' then it works fine, but if the
html script itself contains a ' then i need some way to escape it, no ?

How should i do it if i had something like <HEAD><TITLE='PHP foo'></HEAD>?
Jul 17 '05 #1
12 8745
*** Maxim Vexler wrote/escribió (Thu, 11 Nov 2004 11:35:46 +0200):
If the opening & closing tags are both ' then it works fine, but if the
html script itself contains a ' then i need some way to escape it, no ?


\'

http://es.php.net/manual/en/language.types.string.php

--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Jul 17 '05 #2
Alvaro G Vicario wrote:
*** Maxim Vexler wrote/escribió (Thu, 11 Nov 2004 11:35:46 +0200):
If the opening & closing tags are both ' then it works fine, but if the
html script itself contains a ' then i need some way to escape it, no ?

\'

http://es.php.net/manual/en/language.types.string.php


Note to self : Speak less, Read MORE (manuals).

Thank you. :)
Jul 17 '05 #3
Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:
How should i do it if i had something like <HEAD><TITLE='PHP foo'></HEAD>?


[nit-picking]
Tags and attributes should be lower case
Attribute values should be in double quotes no single.
<title=...> is not valid html; <title>PHP foo</title> is
[/nit-picking]
Jul 17 '05 #4
Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:
If the opening & closing tags are both ' then it works fine, but if the
html script itself contains a ' then i need some way to escape it, no ?


Use \'

Matthias
Jul 17 '05 #5
"Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il>"
wrote in message news:<41********@news.012.net.il>...

Assuming i have this simple script :

<?PHP

//Opening tag ='
$html_header='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
'; // Closing tag ='

echo $html_header;

?>

If the opening & closing tags are both ' then it works fine, but if the
html script itself contains a ' then i need some way to escape it, no ?
Yes. You should escape it with \ or just use the very versatile
heredoc syntax.
How should i do it if i had something like <HEAD><TITLE='PHP foo'></HEAD>?


Option One:

$head = '<HEAD><TITLE=\'PHP foo\'></HEAD>';

Option Two:

$head = "<HEAD><TITLE='PHP foo'></HEAD>";

Option Three:

$head = <<<ENDOFHEAD
<HEAD><TITLE='PHP foo'></HEAD>
ENDOFHEAD;

Cheers,
NC
Jul 17 '05 #6
Nikolai Chuvakhin wrote:
"Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il>"
wrote in message news:<41********@news.012.net.il>...

Assuming i have this simple script :

<?PHP

//Opening tag ='
$html_header='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
'; // Closing tag ='

echo $html_header;

?>

If the opening & closing tags are both ' then it works fine, but if the
html script itself contains a ' then i need some way to escape it, no ?


Yes. You should escape it with \ or just use the very versatile
heredoc syntax.
How should i do it if i had something like <HEAD><TITLE='PHP
foo'></HEAD>?


Option One:

$head = '<HEAD><TITLE=\'PHP foo\'></HEAD>';

Option Two:

$head = "<HEAD><TITLE='PHP foo'></HEAD>";

Option Three:

$head = <<<ENDOFHEAD
<HEAD><TITLE='PHP foo'></HEAD>
ENDOFHEAD;


Option Four:

$head = '<HEAD><TITLE="PHP foo"></HEAD>';

Although of course this isn't valid HTML as the title tag works like this:

<title>PHP Foo</title>

and the tags and attributes should be in lower case because you have defined
XHTML Script as your document type.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #7
Robin Goodall wrote:
Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:
How should i do it if i had something like <HEAD><TITLE='PHP
foo'></HEAD>?


[nit-picking]
Tags and attributes should be lower case
Attribute values should be in double quotes no single.
<title=...> is not valid html; <title>PHP foo</title> is
[/nit-picking]


You *can* use single quotes. I can't find this referenced anywhere, but I
just made a test document in both 1.0 Strict and 1.1 and they both
validated when using single quotes for attribute values.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #8
On Thu, 11 Nov 2004 14:34:54 +0000, Robin Goodall <an**@somewhere.com> wrote:
Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:

How should i do it if i had something like <HEAD><TITLE='PHP foo'></HEAD>?
[nit-picking]
Tags and attributes should be lower case


This is not required, and the examples in the HTML specification have the
element names in upper case.

HTML4.0.1, sec 1.2.1 (Document Conventions, Elements and Attributes):
http://www.w3.org/TR/html4/about.html#h-1.2.1

"Element names are written in uppercase letters (e.g., BODY). Attribute names
are written in lowercase letters (e.g., lang, onsubmit). Recall that in HTML,
element and attribute names are case-insensitive; the convention is meant to
encourage readability."

HTML4.0.1, sec 3.2.1:
http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.1

"Element names are always case-insensitive."
Attribute values should be in double quotes no single.


Single quotes are perfectly acceptable; they're explicitly allowed in the HTML
specification, via the SGML specification:

HTML4.0.1, sec 3.2.2:
http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2

"By default, SGML requires that all attribute values be delimited using either
double quotation marks (ASCII decimal 34) or single quotation marks (ASCII
decimal 39)."

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #9
On Fri, 12 Nov 2004 08:01:41 +1300, Chris Hope <bl*******@electrictoolbox.com>
wrote:
Robin Goodall wrote:
Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:
How should i do it if i had something like <HEAD><TITLE='PHP
foo'></HEAD>?


[nit-picking]
Tags and attributes should be lower case
Attribute values should be in double quotes no single.
<title=...> is not valid html; <title>PHP foo</title> is
[/nit-picking]


You *can* use single quotes. I can't find this referenced anywhere, but I
just made a test document in both 1.0 Strict and 1.1 and they both
validated when using single quotes for attribute values.


It's defined back in the XML spec; see the two alternatives, one for double
quotes and the other for single quotes:

http://www.w3.org/TR/2000/REC-xml-20001006#NT-AttValue

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #10
Andy Hassall wrote:
Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:

How should i do it if i had something like <HEAD><TITLE='PHP
foo'></HEAD>?


[nit-picking]
Tags and attributes should be lower case


This*is*not*required,*and*the*examples*in*the*HTML *specification*have*the
element names in upper case.


Well actually in his example he was using XHTML Strict as the document type
so tags and attributes *must* be in lower case.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #11
On Fri, 12 Nov 2004 08:17:14 +1300, Chris Hope <bl*******@electrictoolbox.com>
wrote:
Andy Hassall wrote:
Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:

How should i do it if i had something like <HEAD><TITLE='PHP
foo'></HEAD>?

[nit-picking]
Tags and attributes should be lower case


This*is*not*required,*and*the*examples*in*the*HTML *specification*have*the
element names in upper case.


Well actually in his example he was using XHTML Strict as the document type
so tags and attributes *must* be in lower case.


Yeah, I cancelled the post after seeing it was XHTML (despite the subject
saying HTML) but it looks like it was too late and the message got out.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #12
Andy Hassall wrote:
Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:
How should i do it if i had something like <HEAD><TITLE='PHP
foo'></HEAD>?

[nit-picking]
Tags and attributes should be lower case
Attribute values should be in double quotes no single.
<title=...> is not valid html; <title>PHP foo</title> is
[/nit-picking]


You *can* use single quotes. I can't find this referenced anywhere, but I
just made a test document in both 1.0 Strict and 1.1 and they both
validated when using single quotes for attribute values.


It's defined back in the XML spec; see the two alternatives, one for
double
quotes and the other for single quotes:

http://www.w3.org/TR/2000/REC-xml-20001006#NT-AttValue


I knew I'd seen it somewhere the other day. Although my eyes normally glaze
over when I try to read DTDs...

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

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

Similar topics

14
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in -...
4
by: VK | last post by:
09/30/03 Phil Powell posted his "Radio buttons do not appear checked" question. This question led to a long discussion about the naming rules applying to variables, objects, methods and properties...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
6
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> ...
3
by: Mochuelo | last post by:
Hi, In the constructor of a class, I am taking as a parameter the reference to a "bool", as in this code: ----------------------- public class TCP_synch_client { public string address...
3
by: Michelle Stone | last post by:
hi al i have "variab1 = window.open ("a.aspx", "helloworld"); i do this inside a RegisterStartupScrict ("key", "<script language=javascript>******</script>"); where ***** is hte javascript...
2
by: mstearne | last post by:
Has anyone seen any Javascript that mimics the effect that allows you to browse through the New Releases, Just Added sections of the iTunes Music Store? Where you click the arrow icon and the next...
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.