This is the P2PU Archive. If you want the current site, go to www.p2pu.org!
You haven't posted any discussions yet.
Here's my codepad of the last question.
How do we get apostrophes in variable names?
For the creation of the last portion...the url, I put the 'dot' of the dot org and of the 'www.' inside the variables. Would like to see how others are handling the url creation.
One way could be http://codepad.org/FlOJFRpe
Hi there,
This is how I went about it:
http://codepad.org/xqLmNQR5
basically the same as Aryeri although I have a different URL!
Does anyone know if one of these is 'more' correct:
echo "http://" .$url4 ."." . $url3 ."." . $url1 . "/". $url2; OR
echo "http://" . $url4 . "." . $url3 . "." . $url1 . "/p2pu-" . $url2;
in terms of the way that spaces have been put between the concatenated '.'. Does a space in fact matter?
You can see a number of examples here: http://codepad.org/4Fs9bPje
The short answer is simply that, no, the PHP parser doesn't care if you put one, two, or no spaces around the concatenation operator. But at the same time, it does matter. If you look at the example link I pasted above, you can see that the line with spaces is easier to read. And that's why most programmers put spaces around all their operators.
echo '$chunk1 $chunk2' . PHP_EOL;
I think that the above does NOT work due to the single quotes - code is not executed in the single quotes?
---
printf('%s %s' . PHP_EOL, $chunk1, $chunk2);
This one has me baffled! I'm guessing that the %s (1st) is related to $chunk1 and the 2nd %s to $chunk2 - but why... I don't know.
Thanks for the heads-up with PHP_EOL too - that's nice. I'm guessing that I will be using Linux 99.9% of the time, but it's always good to know.
Spot on, Nathan. The difference between single and double quotes is that in single quotes, the PHP parser doesn't interpret any of the contents and just presents them literally. This includes not translating variables into their values, and it also means that escaped characters (like \t for tag, \n for line-feed) are not translated either. Single-quotes are good when you want the string to be totally literally with no substitution.
Sorry that printf() was baffling. I was just sharing a completely different way -- "for fun", as I wrote -- but since I brought it up, yes, you're basically right. printf() uses substitution placeholders in its format string. %s means to render a variable as a string (as opposed to as an integer, float, or some other type of value). It maps the placeholders in order to the variable arguments. In this case, then, the first %s is replaced by $chunk1 formatted as a string, and the second %s is replaced by $chunk2. You can actually get quite fancy with the placeholders, that was a very basic example. I just threw it in for fun, but great job tackling it and you intuited well.
As for using Linux almost exclusively, keep in mind that if you contribute or share your code, it may find its way onto a Windows computer. I recommend using PHP_EOL simply because it's a good habit to get into. It'll never be wrong, and it can be very helpful in cases where you might not have expected the code could eventually end up on Windows and does. Or vice versa for the Windows crowd who don't expect to run their code on Linux, a Unix (which includes Mac OS X).
According to this http://php-faq.com/#110 "Inside double quotes variables will be converted into their values"
<?php
echo "http://$url4.$url3.$url1/p2pu-webcraft";
?>
which is a lot easier for me to read and less to type.
Your method is MUCH more elegant than mine - I will try to remember that from now on.
Thanks.
Ah, that's great!
Please help me with the third part of the assignment. I don't understand the question. By typing "echo $c*2;" I'm not modifying the values, nor creating new variables, but it can't be the answer. I don't know what to do((
Thanks
You need to combine the variables using mathematical operators to produce the desired answers.
Oh, got it.
Thank you!
Good job helping each other out! That's exactly what we want to see. :)
Hi all!
Here's my codepad for the 4th question.
http://codepad.org/xDqYWuUP
Please tell me what I'm doing wrong.