Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 6th, 2005, 10:28 AM   #1
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
substr problems.

hey,

i am having trouble with the php function substr. He's the function that i am working on:

[PHP]
function page_name($url)
{
//this function returns the part of the page name infront of the _
$chunks = explode("/", $url);
$temp = count($chunks);
$res = strpos($chunks[$temp - 1], "_");
if ($res === false)
{
//then we have the index page.
return "index";
}
else
{
//then we have a match.
//it means that the page isn't index.php
//grab everything before the _
$length = strlen($chunks[$temp - 1]);
$numchar = $length - $res;
$length = $length * (-1);
$page = substr($chunks[$temp - 1]), $length, $numchar); //this is the line that has caused the error.
return $page;
}
}
[/PHP]

anyways, when calling this function i send the $PHP_SELF for the url parameter. I get the error:

Quote:
Parse error: parse error, unexpected ',' in /home/nick/CandoWeb-New/menu-split.php on line 30


Any ideas?
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Apr 6th, 2005, 10:31 AM   #2
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
check the brackets on the line

1 open 2 close
Berto is offline   Reply With Quote
Old Apr 6th, 2005, 10:49 AM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
damit, i don't know why i didn't see that.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Apr 6th, 2005, 12:46 PM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
yep, missing a paranthesis.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Apr 6th, 2005, 1:24 PM   #5
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
one to many :-)
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Apr 6th, 2005, 2:30 PM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
or one too less, depending on how ya look at it


$page = (substr($chunks[$temp - 1]), $length, $numchar);
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Apr 6th, 2005, 3:40 PM   #7
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Just a suggestion...

[php]
function page_name($url) {
$url = explode("_", basename($url));
return $url[0];
}
[/php]
__________________

tempest is offline   Reply With Quote
Old Apr 7th, 2005, 3:15 AM   #8
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
Quote:
Originally Posted by Infinite Recursion
or one too less, depending on how ya look at it


$page = (substr($chunks[$temp - 1]), $length, $numchar);

that would still cause an error as substr is 3 arguments not 1 :-p
Berto is offline   Reply With Quote
Old Apr 7th, 2005, 7:51 AM   #9
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Berto is right...

[php]$page = substr($chunks[$temp - 1], $length, $numchar);[/php]

However the variable names seem odd when knowing the arguments for substring are as follows....

substr (arguments):
  1. String
  2. Position of first character to begin substring sequence
  3. Length to go from first character to get to end of anticipated substr
I'm a bit confused on what you're trying to do. But i think this may be it...

[php]$page = substr($chunks[$temp - 1], $numchar, $length);[/php]
__________________


Last edited by tempest; Apr 7th, 2005 at 7:54 AM.
tempest is offline   Reply With Quote
Old Apr 7th, 2005, 8:32 AM   #10
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
yeah the code was flawed. i fixed it to look like this:

[PHP]
function page_name($url)
{
//this function returns the page that is currently calling this funtion.
$chunks = explode("/", $url);
$temp = count($chunks);
$res = strpos($chunks[$temp - 1], "_");
if ($res === false)
{
//then we have the index page.
return "index";
}
else
{
//then we have a match.
//it means that the page isn't index.php
//grab everything before the _
$length = strlen($chunks[$temp - 1]);
$length = $length * (-1);
$page = substr($chunks[$temp - 1], $length, $res); //get the page.
return $page;
}
}
[/PHP]

and yes i name my varibles stupidly sometimes. but as long as i know what's going on, then it doesn't bother me.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:51 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC