trying to combine a print stmt

This is a discussion on trying to combine a print stmt within the PHP Language forums, part of the PHP Programming Forums category; Thanks ahead for your help I'm trying to learn what I can do with echo and print statements. I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-02-2005
mmccaws
 
Posts: n/a
Default trying to combine a print stmt

Thanks ahead for your help

I'm trying to learn what I can do with echo and print statements. I
figured out the echo statement and below is the simple version using
print. I've tried two dozen or more single print statements, first
start with the first part then adding additional phrases, then looking
at the page source code, but I'm missing something simple,(isn't that
always the way) What I'm trying to understand is how, if it's possible,
to combine the three statements into one print statement. If this
isn't possible will printf work?

print("<a href=\"login.php?");
print(session_id());
print("&whichpage=$i\">login link $i</a>");

Thanks
Mike

Reply With Quote
  #2 (permalink)  
Old 03-02-2005
Senator Jay Billington Bulworth
 
Posts: n/a
Default Re: trying to combine a print stmt

"mmccaws" <mmccaws@netscape.net> wrote in news:1109734363.485993.172740
@g14g2000cwa.googlegroups.com:

> Thanks ahead for your help
>
> I'm trying to learn what I can do with echo and print statements. I
> figured out the echo statement and below is the simple version using
> print. I've tried two dozen or more single print statements, first
> start with the first part then adding additional phrases, then looking
> at the page source code, but I'm missing something simple,(isn't that
> always the way) What I'm trying to understand is how, if it's possible,
> to combine the three statements into one print statement. If this
> isn't possible will printf work?
>
> print("<a href=\"login.php?");
> print(session_id());
> print("&whichpage=$i\">login link $i</a>");


Yes, you can combine print statements using the concatenation operator (the
period). For example,

print '<a href="login.php?' . session_id() . "&whichpage=$i\">login link $i
</a>";

Basically, you just take the items you're printing on each individual print
statement, and string them all together with periods on a single line.
Another tip from the code above, in the first section of the print
statement. If you're printing out a string that contains question marks but
no variables and no single-quotes, you can surround the string in single-
quotes and avoid the need to escape the quotation mark.

hth

--

Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Reply With Quote
  #3 (permalink)  
Old 03-02-2005
NC
 
Posts: n/a
Default Re: trying to combine a print stmt

mmccaws wrote:
>
> how, if it's possible, to combine the three statements
> into one print statement.
>
> print("<a href=\"login.php?");
> print(session_id());
> print("&whichpage=$i\">login link $i</a>");


Here are some options:

1. Use concatenation operator:

print "<a href=\"login.php?" . session_id() .
"&whichpage=$i\">login link $i</a>";

2. List multiple arguments (won't work with print though,
only with echo):

echo "<a href=\"login.php?", session_id(),
"&whichpage=$i\">login link $i</a>";

3. Combine multiple strings into one before output:

$sid = session_id();
print "<a href=\"login.php?$sid&whichpage=$i\">login link $i</a>";

Cheers,
NC

Reply With Quote
  #4 (permalink)  
Old 03-02-2005
Michael Fesser
 
Posts: n/a
Default Re: trying to combine a print stmt

.oO(mmccaws)

>print("<a href=\"login.php?");


HTML also allows single quotes around attribute values.

> print("&whichpage=$i\">login link $i</a>");

^
This has to be &amp; in order to be valid HTML.

Micha
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:36 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0