Code isnt working correctly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Code isnt working correctly

Post 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?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You forgot to return the $result ;)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Sorry for the vague title, but I couldn't think of one. Oh well...
How about "Troublesome portal explosion"?
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post 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
Post Reply