How do you change link text with PHP?

  • Tabble
  • Born
  • Born
  • Tabble
  • Posts: 4

Post 3+ Months Ago

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?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Sabu
  • Beginner
  • Beginner
  • Sabu
  • Posts: 47

Post 3+ Months Ago

You didn't make it very clear exactly what you want done with them.. perhaps you could provide an output sample?

so you have a couple of thousand files, each of them containing a list of songs and artists

you want some to say "artist tab" and some to say "artist" as a tab.

hmm..

PHP Code: [ Select ]
 
/within the usual foreach, or whatever you choose
 
 
 
$linkarray = explode("-",$word);
 
$songname = $linkarray[1];
 
$songname = ucwords($songname);
 
// $linkarray[0] is the artist name, underscores included
 
echo "<a href='".$linkarray[0]."/".$word.".php'>".$songname."</a>";
 
 
  1.  
  2. /within the usual foreach, or whatever you choose
  3.  
  4.  
  5.  
  6. $linkarray = explode("-",$word);
  7.  
  8. $songname = $linkarray[1];
  9.  
  10. $songname = ucwords($songname);
  11.  
  12. // $linkarray[0] is the artist name, underscores included
  13.  
  14. echo "<a href='".$linkarray[0]."/".$word.".php'>".$songname."</a>";
  15.  
  16.  



[edit] $word would be, for example, "rolling_stones-paint_it_black"
  • Sabu
  • Beginner
  • Beginner
  • Sabu
  • Posts: 47

Post 3+ Months Ago

if you wanted to only show the artist name once for each set, you could do something along the lines of

- Arranging the 'word' array alphabetically
- setting some random variable, say $lastshown to be the name of the last artist name printed
- check, each loop, if the artist name is the same as $lastshown. If it isn't, show the name then set $lastshown to be the new name.[/list]

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 132 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.