Is There any function at PHP just like qq() ,q() at PERL?
Moderator: General Moderators
Is There any function at PHP just like qq() ,q() at PERL?
Is There any function at PHP just like qq() ,q() at PERL?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
""'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
http://www.gossamer-threads.com/forum/G ... ~_P246128/
or how about
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.
or how about
Code: Select all
<?php
function qq($val){
return '"'.$val.'"';
}
?>For Example
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>
);Well, you still didn't explain what this is supposed to do, or what the output should be.
Whats so unique about this, vs.
...and what is this supposed to do that
doesn't? My perl book doesn't seem to have qq and you are not a very good teacher.
Code: Select all
<?php
$sql=qq( select id, name from $tb where id = '$id' );
?>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>
);
?>Code: Select all
<?php
$str = $str.AddSlashes( "
<option value="$row['name']" selected >
$row['name']
</option> "
);
?>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;