View Full Version : Something like qq~Text~; (from Perl) in PHP?

07-11-2002, 01:48 PM
In Perl I use qq~Some text~; a lot and I'm looking for something like this in PHP.

For those who don't know perl, let me explain what it does:
It enables you to write on multiple lines without extra functions (is possible in PHP with just the "Text [new line] more text")
But it also makes it possible to write text whitout have to escape all characters; like ", <, $, etc.


Thanks in advance,
Mzzl, Chris

07-11-2002, 03:16 PM
In php to write on a new line just do

echo "some text \n more text on another line"
Note : This will make a new line in the source code. If you want a new line on the screen you need to replace the \n by <br>
You don't need to escape $ and < in php. Just " or ' and \ I think

07-11-2002, 03:48 PM

If your in a conditional loop I think this works (although I haven't tried it)

if(some_condition) {//write if condition is true

<table border="5" cellpadding="1">
<tr><td>This is the life, I'm going to write a backslash \.</td></tr>

}// end writing
else {// begin writing for false condition

Nope ain't gonna do it! OK?

}// end false condition writing

07-11-2002, 04:40 PM
It does work ;)

And not only in conditions, just anywhere

07-11-2002, 04:44 PM
Additionally, perhaps the heredoc syntax is suited to your needs. Although it parses variables still... have a look at


07-11-2002, 06:41 PM
You an also just exit out of the PHP block and print HTML directly (which is, technically, faster than doing ECHO, from a machine speed/time point of view). Of course, then you are going to have to enclose any of your variables with <?= and ?>.

//preceding code, if any
if ($c['noticestat']) {
//html block
<html lang="en_US">
<body bgcolor="#000000" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
<td width="100%" height="100%" align="center" valign="middle" class="noticeTxt"><?=$c['noticemess'];?><br/>
<br/>.( <?=$c['sitename'];?> ).</td>
//back to PHP
//additional code, if any

Edit : evil missing bracket!

07-11-2002, 09:35 PM
That "exiting" PHP is a good idea and solves my problem, for a part, but I'd also like to know if there's a way in wich I don't have to escape "...

Thanks to all of you for your help.

07-11-2002, 10:23 PM
Yup, this can be done... like so

<form name="edit=web" method="post" action="edit_Prem_table.php?edit=1&id=<?=row[id];?>">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td valign="middle" width="20%">
<div align="center">
print $row["team"];
<td width="20%" valign="middle">
<div align="center">
<input type="text" class="formfield" name="newplayed" size="2" value="

Hope that is clear... the code thingcan be anyhting!


07-11-2002, 10:59 PM
Thanks, that's it