Page 1 of 1
Is There any function at PHP just like qq() ,q() at PERL?
Posted: Fri Aug 01, 2003 7:49 am
by saloufeng
Is There any function at PHP just like qq() ,q() at PERL?
Posted: Fri Aug 01, 2003 8:04 am
by twigletmac
What does q()/qq() do?
Mac
Posted: Fri Aug 01, 2003 8:19 am
by saloufeng
q/STRING/
""'STRING'""
A single-quoted, literal string. A backslash rep-
resents a backslash unless followed by the delim-
iter or another backslash, in which case the
delimiter or backslash is interpolated.
$foo = q!I said, "You said, 'She said it.'"!;
$bar = q('This is it.');
$baz = '\n'; # a two-character string
qq/STRING/
""STRING""
A double-quoted, interpolated string.
$_ .= qq
(*** The previous line contains the naughty word "$1".\n)
if /\b(tcl|java|python)\b/i; #

$baz = "\n"; # a one-character string
Posted: Fri Aug 01, 2003 10:09 am
by jmarcv
http://www.gossamer-threads.com/forum/G ... ~_P246128/
or how about
Code: Select all
<?php
function qq($val){
return '"'.$val.'"';
}
?>
An example of why you want to use it would help. You give some definition examples, but no example of the output that would be generated.
For Example
Posted: Fri Aug 01, 2003 10:55 am
by saloufeng
such as in PERL I can use:
Code: Select all
$sql=qq( select id, name from $tb where id = '$id' );
$str = $str.qq(
<option value="$row->{name}" selected >
$row->{name}
</option>
);
Posted: Fri Aug 01, 2003 11:15 am
by jmarcv
Well, you still didn't explain what this is supposed to do, or what the output should be.
Code: Select all
<?php
$sql=qq( select id, name from $tb where id = '$id' );
?>
Whats so unique about this, vs.
Code: Select all
<?php
$sql=qq( select id, name from $tb where id = '$id' );
?>
Code: Select all
<?php
$str = $str.qq(
<option value="$row->{name}" selected >
$row->{name}
</option>
);
?>
...and what is this supposed to do that
Code: Select all
<?php
$str = $str.AddSlashes( "
<option value="$row['name']" selected >
$row['name']
</option> "
);
?>
doesn't? My perl book doesn't seem to have qq and you are not a very good teacher.
Posted: Fri Aug 01, 2003 11:34 am
by saloufeng
I use qq() just to make my code tidy.
if there are single-quoted , double-quoted and Variable in the String,
I hope for less quoted and "." in the code;
In perl qq() can do this, and How to do this in PHP?
Posted: Fri Aug 01, 2003 11:45 am
by nielsene
I don't beleive PHP has a corresponding function.
addslashes() is somewhat similar, but not exact.
PHP will not let you stick a non-quoted string into a variable, so you have to quote it somehow. I'm still at a loss for why q/qq are useful.
Posted: Fri Aug 01, 2003 12:09 pm
by nielsene
Perhaps look at the HEREDOC syntax, it might accomplish your goals of fewer quotes/concatenations.
Code: Select all
$foo=<<<END_DOC
Hello, my name is $name.
This is a multi-line HEREDOC.
Variables are interpolated, newlines are preserved, without need \n
The string ends when a matching indentifier as used on the first line (END_DOC) is found that begins at the start of a line.
END_DOC;