How do you change link text with PHP?
I'm building a website with over 3000 index.php pages and within these pages, are a listing of links that all look like this for example:
rolling_stones-paint_it_black
led_zeppelin-kashmir
pink_floyd-comfortably_numb
Notice how artist/band is seperated by song with the " - ".
What'd I'd like the links to say, using the examples above, are just "Paint It Black Tab", "Kashmir Tab" and "Comfortably Numb" Tab, so it would have to somehow cut off, or not display artist/band for every link, capitalize the beginning of every word, change the _'s to spaces, and add the word "Tab" after ever link.
These links are allready pre-generated and embedded into the index.php pages, and there's no way I can make them generate anything other than like the example links above.
Does anyone know how to do this? Is it even possible?
Suzanne posted this at 23:39 — 5th June 2004.
She has: 5,507 posts
Joined: Feb 2000
Where the links are generated, you can add code to truncate the line, although it would seem more likely that you would be able to edit the generated code to what you wanted.
Renegade posted this at 02:44 — 6th June 2004.
He has: 3,022 posts
Joined: Oct 2002
Well, what about splitting the string by the "-"? then get the second part and replace the "_" with a " ". The following code is not tested but I think it would look something similar to it.
<?php
$string = \"rolling_stones-paint_it_black\";
$string = explode($string, \"-\"); // firstly, splitting up the string by the \"-\"
$new_string = str_replace(\"_\", \" \", $string[1]); // next, replacing all stances of the \"_\" with a \" \"
$new_string = ucwords($new_string); // then, capitalise the words
$new_string = $new_string . \"Tab\"; // finally, add \"Tab\" to the end.
?>
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.