473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

Jul 17 '05 #1
3 2232
"mmccaws" <mm*****@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
Jul 17 '05 #2
NC
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

Jul 17 '05 #3
.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
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Art | last post by:
Hello, I can't seem to get eval or compile to accept the print stmt, or any complicated statements. The documentation I've looked out doesn't explain why this is. ex: >>>...
2
by: claus.hirth | last post by:
I wrote a stored procedure that uses a prepared INSERT INTO statement in order to play with the PREPARE and EXECUTE keywords. In transcript 1 below the call to that stored procedure does not...
24
by: trint | last post by:
add them into one PrintDocument: PrintDocument pd1 = new PrintDocument(); PrintDocument pd2 = new PrintDocument(); PrintDocument pdCombined = new PrintDocument(); pdCombined = pd1 + pd2;...
1
by: Uzytkownik | last post by:
I've some function: function show($id) { $title = $text = $date = $nick = NULL; $stmt = $this->base->stmt_init(); $stmt->prepare("SELECT title,text,datetime,nick FROM posts LEFT JOIN authors ON...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
3
by: Steven Bethard | last post by:
Within a larger pyparsing grammar, I have something that looks like:: wsj/00/wsj_0003.mrg When parsing this, I'd like to keep around both the full string, and the AAA_NNNN substring of it, so...
7
by: SNN | last post by:
Hi, I have 4 files that I would like to combine side by side and the seperater is tab in these four files. I also would like to have the output file to be tab delimited. All 4 files have the same...
5
by: Yew12 | last post by:
I have been trying to update the details in a access database but, all I get is a white screen and all the errors I have built-in give me no help at all. All help is greatly appreciated. ...
20
by: arnimavidyarthy | last post by:
Hi, Hi, I am taking a string as an input from the user and it should only contain the chars:L , M or R I tried the folllowing in kodos but they are still not perfect:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.