...

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



chrisvmarle
07-11-2002, 12: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.

Anyone?

Thanks in advance,
Mzzl, Chris

Flamerule
07-11-2002, 02: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

bcarl314
07-11-2002, 02:48 PM
Also,

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

<?php
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>
</table>

<?php
}// end writing
else {// begin writing for false condition
?>

Nope ain't gonna do it! OK?

<?php
}// end false condition writing
?>

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

And not only in conditions, just anywhere

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

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

Feyd
07-11-2002, 05: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">
<head>
<title><?=$title['curvar'];?></title>
</head>
<body bgcolor="#000000" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td width="100%" height="100%" align="center" valign="middle" class="noticeTxt"><?=$c['noticemess'];?><br/>
<br/>.( <?=$c['sitename'];?> ).</td>
</tr>
</table>
</body>
</html>
<?
}
//back to PHP
//additional code, if any
?>


Edit : evil missing bracket!

chrisvmarle
07-11-2002, 08: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.

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



echo<<<code
<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">
<tr>
<td valign="middle" width="20%">
<div align="center">
code;
print $row["team"];
echo<<<code
</div>
</td>
<td width="20%" valign="middle">
<div align="center">
<input type="text" class="formfield" name="newplayed" size="2" value="
code;


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

Jee

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum