journal
all all entries rss SoML excited dreams runes YRUU ultimate KTRU skate sleepy nihongo
Rob is 20,118 days old today.

Entries this day: Natalia's_apartment_with_Fatima php_printing

Natalia's apartment with Fatima

7:44pm JST Sunday 19 October 2008 (day 14088)

Fatima and I have enjoyed a lovely afternoon with Natalia at her new apartment near Ichigaya. Because Fatima only had like 3 hours of sleep, I had to wake her up before we left, and she's taken some naps since we ate, but she's awake now.

Natalia is speed chatting in Spanish (I would use the Spanish word to write Spanish, but the current Shift-JIS encoding won't encode the fifth character. Gotta change my journal to UTF-8, but not sure how to re-encode everything.

Fatima has two new friends: Mr Poof, a large overstuffed beanbag (cube shaped), and Kiri, her name for Uncle Cow, who she's going to take to her work (Gas Panic in Shibuya) tomorrow night.

permalink

php printing

7:42pm JST Sunday 19 October 2008 (day 14088)

Jesse's been working on a PHP project for his church Christmas event. He wrote to me, using our old hackey sack names:

Dr. Kick,

Can you give me some tips about echo.

Example, mixing variable and HTML on one line. When is print more appropriate?

Echo and arrays vs print, printr and arrays.

The web tuts are not so detailed ,ad don't put such tricks you seem to know.

Turbo

My reply:

	
Konnichiwa, Stall-san.

I'm traveling in Japan at the moment, so I don't know if I can give a great answer, but I think:

echo just prints stuff straight to the screen.  It's not good for printing arrays, but it can print scalar text and html just fine.

print_r can print to the screen or into a variable.

It's something like

$greeting = print_r("hello" . $name,true);   // true means print to the variable, and not to the screen.

print_r can print arrays, nicely formatted:

print_r($array);

and the output will be easy for you to read (*).  I've never had a reason to write arrays out to users in that way, but I use it for debugging a lot.

(*) if you're writing to a web browser, you need to basically do this:

echo "<pre>";  // or use print_r("<pre>");   but echo doesn't require parenthesis
print_r($array);
echo "</pre>";

I wrote a function

function print_rob($item)
{
    echo "<pre>";
    print_r($array);
    echo "</pre>";
}

So it prints the <pre> tags for me so I can easily read the output on the web browser.

And that's about the extent of my php printing prowess.

(I know php has a printf function, which allows formatted printing a la C, but I don't know its syntax by heart.)

I learned most things I know about PHP from http://php.net/

   Dr Kick

-- 
Freestyle art and healing
drkick@robnugen.com
permalink