0

I'm trying to make a little php function so I can easily create and change links in my website. I am using a jQuery plugin for hash pages, which is what my website is driven on, all hash based website, so I use this a lot and at some point if I want to change the URL setup it would take forever to go through each place and do it.

I've got something like this right now, which would work for the first two variables, but the problem is there could just be one variable returned sometimes, and other times there could be 2, or 4, and in the future even more than the four i have defined.

function href($page, $pageID, $subPage, $subPageID)
{

$href = 'href="#/'.$page.'/'.$id.'" rel="address:/'.$page.'/'.$id.'"';

return $href;   
}

The finished links would look like these:

<a href="#/home" rel="address:/home"></a>

and or

<a href="#/profile/1" rel="address:/profile/1"></a>

and or

<a href="#/profile/1/subPage/2" rel="address:/profile/1/subPage/2"></a>

etc.

and I would like to accomplish this using the function, and the usage would be something along the lines of:

<a <?php echo href('home')?>></a>

and or

<a <?php echo href('profile', '1')?>></a>

and or

<a <?php echo href('profile', '1', 'subPage')?>></a>

etc.

Any help with how to solve this would be greatly appreciated, thanks!

1

1 Answer 1

1

Try this:

function href(){
    $url = implode('/', func_get_args());
    $href = 'href="#/'.$url.'" rel="address:/'.$url.'"';
    return $href;   
}

When calling href('hello', 'world', '1');, it should return the string

href="#/hello/world/1" rel="address:/hello/world/1"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.