Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

forcing double quotes

2 views
Skip to first unread message

richard

unread,
May 25, 2012, 1:30:55 AM5/25/12
to

echo "<a href='#'>"

how do you make it so that the output will show "#"?
&quot; in place of the ' does not work.

Olaf S.

unread,
May 25, 2012, 2:26:58 AM5/25/12
to
echo '<a href="#">#</a>';


Shake

unread,
May 25, 2012, 3:54:08 AM5/25/12
to
echo '<a href="#">';

Or

echo "<a href=\"#\">";

Greetings

The Natural Philosopher

unread,
May 25, 2012, 4:46:42 AM5/25/12
to
echo "<a href=\"#\">";

or

echo '<a href="#">';

--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

Scott Johnson

unread,
May 25, 2012, 7:54:45 AM5/25/12
to
If you are working with many tags that you have to have in double quotes
and don't want to have many escapes I find this works very well for me.

Heredocs

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

<?php
// off the cuff
define("SITE_NAME", "SiteName");
$id = 1;
$alt_color = "yellow";
$content = "http://" . SITE_NAME;

$link = <<<EOD // Must be on its own line but not needed to be first.
<table border="0" cellpadding="0" cellsapcing="0">
<tr class="tr_class">
<td style="border-bottom:1px solid gray; color:{$alt_color};">
<a href="http://{$content}?id={$id}">{$content}</a>
</td>
</tr>
</table>
EOD; // Must be first and only on its own line.

echo $link;

?>

Thomas 'PointedEars' Lahn

unread,
May 25, 2012, 9:04:12 AM5/25/12
to
PHP is the *P*HP *H*ypertext *P*reprocessor. Use it:

<?php

?><a href="#">#</a><?php

<?php

?>

(Insert line-breaks where convenient, but be aware that they result in
whitespace text nodes which in turn may result in a space character being
displayed. Consult the HTML 4.01 Specification for details.)

This approach (stdin – parse – stdout) wins over a here-doc string in almost
all cases, as by contrast the ending delimiter of a here-doc string must be
at the first column (so is not easy to indent), can only be followed by at
least a semicolon (which means concatenation for more complex expressions),
and requires escaping of some characters that do not have to be escaped with
the approach above.

Incidentally, it is described and recommended by one of the first chapters
of the PHP manual:

<http://php.net/manual/en/tutorial.firstpage.php>

It should also be noted that PHP 5.4 does away with the nonsense that
`<?= … ?>' would not be working with short_open_tag=Off (which required you
to write `<?php echo …; ?>' instead), so there is no good excuse left to
`echo' *everything* (instead of just the dynamic parts) rather ineffiently:

<http://php.net/ChangeLog-5.php>


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

Thomas 'PointedEars' Lahn

unread,
May 25, 2012, 9:22:50 AM5/25/12
to
[Cancel & Supersedes: Sorry, copy-and-paste error resulting in invalid code]
PHP is the *P*HP *H*ypertext *P*reprocessor. Use it:

<?php

?><a href="#">#</a><?php

Markus Sonnenberg

unread,
May 25, 2012, 9:57:52 AM5/25/12
to
echo "<a href=\"#\">"; does that work?

ct,
--
Das Abspringen einer Begrenzungsmauer dient nicht dem direkten
Zurücklegen des Arbeitsweges.
http://www.rz-amper.de

Michael Fesser

unread,
May 25, 2012, 3:19:01 PM5/25/12
to
.oO(richard)

>echo "<a href='#'>"
>
>how do you make it so that the output will show "#"?
>&quot; in place of the ' does not work.

What's wrong with the single quotes? HTML doesn't care.

Micha

--
http://mfesser.de/blickwinkel

Olaf S.

unread,
May 25, 2012, 3:57:28 PM5/25/12
to
Am 25.05.2012 15:22, schrieb Thomas 'PointedEars' Lahn:
> [Cancel& Supersedes: Sorry, copy-and-paste error resulting in invalid code]
>
> Olaf S. wrote:
>
>> Am 25.05.2012 07:30, schrieb richard:
>>> echo "<a href='#'>"
>>>
>>> how do you make it so that the output will show "#"?
>>> &quot; in place of the ' does not work.
>>
>> echo '<a href="#">#</a>';
>
> PHP is the *P*HP *H*ypertext *P*reprocessor. Use it:
YES SIR!

>
> <?php
> …
> ?><a href="#">#</a><?php
> …
> ?>
>
He asked with ECHO. And that is PHP.

Olaf


Beauregard T. Shagnasty

unread,
May 25, 2012, 4:35:43 PM5/25/12
to
Olaf S. wrote:

> He asked with ECHO. And that is PHP.

richard doesn't know what he wants, because he has no clue about writing
server-side PHP code...

--
-bts
-This space for rent, but the price is high

Scott Johnson

unread,
May 26, 2012, 10:09:30 AM5/26/12
to
On 5/25/2012 1:35 PM, Beauregard T. Shagnasty wrote:
> Olaf S. wrote:
>
>> He asked with ECHO. And that is PHP.
>
> richard doesn't know what he wants, because he has no clue about writing
> server-side PHP code...
>

I kind of just realized that myself and think my example might of been
over-kill.
0 new messages