Page 1 of 1

Code isnt working correctly

Posted: Sun Aug 27, 2006 1:08 am
by toasty2
Sorry for the vague title, but I couldn't think of one. Oh well...

I'm finally getting some progress on my portal system. But, Ive hit a wall, this seemingly perfect code does not work as it should:

Code: Select all

<?php
function find($string,$opener,$closer)
{
$part1 = explode($opener,$string);
$part2 = explode($closer,$part1[1]);
$result = $part2[0];
}
$string = '<dataset><title>title</title><content>lol content</content></dataset>';
$title = find($string,"<title>","</title>");
echo ("Title: $title");
?>
It is outputting "Title: " instead of "Title: title". What's the deal here?

Posted: Sun Aug 27, 2006 1:22 am
by timvw
You forgot to return the $result ;)

Posted: Sun Aug 27, 2006 5:37 am
by Ollie Saunders
Sorry for the vague title, but I couldn't think of one. Oh well...
How about "Troublesome portal explosion"?

Posted: Sun Aug 27, 2006 9:10 am
by toasty2
Thanks a ton. I don't use functions much, so I forgot about return.

Ole, I might've thought longer if I had time. I wrote that in a hurry. But, good title idea...doesn't matter now, problem solved :D