![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Programming Guru
![]() ![]() |
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:
Any ideas?
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
check the brackets on the line
1 open 2 close ![]() |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() |
one to many :-)
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#7 |
|
Programming Guru
![]() |
Just a suggestion...
[php] function page_name($url) { $url = explode("_", basename($url)); return $url[0]; } [/php]
__________________
|
|
|
|
|
|
#8 | |
|
Programming Guru
![]() |
Quote:
that would still cause an error as substr is 3 arguments not 1 :-p |
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() |
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):
[php]$page = substr($chunks[$temp - 1], $numchar, $length);[/php]
__________________
Last edited by tempest; Apr 7th, 2005 at 7:54 AM. |
|
|
|
|
|
#10 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|