473,835 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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='P HP foo'></HEAD>?
Jul 17 '05 #1
12 8862
*** 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='P HP 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='P HP foo'></HEAD>?


Option One:

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

Option Two:

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

Option Three:

$head = <<<ENDOFHEAD
<HEAD><TITLE='P HP 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='P HP
foo'></HEAD>?


Option One:

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

Option Two:

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

Option Three:

$head = <<<ENDOFHEAD
<HEAD><TITLE='P HP 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='P HP
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='P HP 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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #9
On Fri, 12 Nov 2004 08:01:41 +1300, Chris Hope <bl*******@elec trictoolbox.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='P HP
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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #10

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

Similar topics

14
13094
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 - ImageName - for processing, or the return data which is done (or not as the case may be) by imagejpeg($img) in the script, after header("Content-type: image/jpeg"). Any insights would be most welcome, especially debugging techniques and a pointer to...
4
8410
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 in JavaScript/JScript and HTML/XML elements. Without trying to get famous :-) but thinking it would be interesting to others I decided to post the following summary: 1. Variable names in JavaScript/JScript
12
6565
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 courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
15
6050
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 use. http://www.interactivetools.com/products/htmlarea/ This only works with IE5.5+. What I need to do is to take this html formatted text and only display part of the text on a web page (much like a news article which shows only part of the...
6
5275
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> My question is how do I access the document DOM of this object in Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and produces an unknown error. I'd like to both read and write to the document's body element's innerHTML...
3
8667
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 =""; public int port =0;
3
7343
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 comman i need to access variab1 from some other forms (to close it from another link from the parent's parent's parent's page). i figured out that the best way to do this is to store this javascript variable in a session variable now comes the...
2
2146
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 4 albums are shown. Example: http://imac2.taxrecords.com/mstearne/misc/Picture3.png Thanks, Michael
1
4089
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 hotspots on the image. One being correct(a) and the other incorrect(b). When the user clicks on the correct hotspot or place on the image, it should score and retain that value until the end of the quiz. At the end of the quiz, there is a submit button...
0
9653
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,...
0
10815
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, 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...
0
10524
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10562
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10236
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7768
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6968
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();...
1
4434
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
2
3997
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.