I am trying to teach myself PHP from O'Reilly's Understanding PHP book. I have followed early examples which have worked fine except that the escape sequences in double-quoted strings aren't working properly.
I am using MAMP (php 5.1.6), writing code with textmate, and testing with both Safari & Firefox (os x).
I'm hoping that this is something really simple - i can't find any documentation on this problem anywhere.
noob - Escape sequences - \n, \r not working
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Without seeing any code or knowing the precise situation this is difficult to answer.
If you are wanting to see a blank line in HTML you need to use "<br />" not "\n". As has already been stated the \n only shows up when you view the source code.
The other problem some people have is they include \n in single quote block strings which do not work.
If you are wanting to see a blank line in HTML you need to use "<br />" not "\n". As has already been stated the \n only shows up when you view the source code.
The other problem some people have is they include \n in single quote block strings which do not work.
Code: From O'reilly book
feyd | Please use
I would expect this to display:
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
This is the code that I am trying:Code: Select all
$person[0] = "Edison";
$person[1] = "Wankel";
$person[2] = "Crapper";
$creator['Light bulb'] = "Edison";
$creator['Rotary Engine'] = "Wankel";
$creator['Toilet'] = "Crapper";
The array( ) construct creates an array:
$person = array('Edison', 'Wankel', 'Crapper');
$creator = array('Light bulb' => 'Edison',
'Rotary Engine' => 'Wankel',
'Toilet' => 'Crapper');
foreach ($person as $name) {
echo "Hello, $name\n";
}
foreach ($creator as $invention => $inventor) {
echo "$inventor created the $invention\n";
}instead I get this:Hello, Edison
Hello, Wankel
Hello, Crapper
Edison created the Light bulb
Wankel created the Rotary Engine
Crapper created the Toilet
Hello, Edison Hello, Wankel Hello, Crapper Edison created the Light bulb Wankel created the Rotary Engine Crapper created the Toilet
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]