soltek Posted January 4, 2011 Share Posted January 4, 2011 This may sound weird, but since lately I've found so many weird php built-functions, I chose to give it a try. I'm doing some sort of rating system where the result is given by images of stars. If the value of that rating is giving me the number seven, it'd display seven stars and here's the deal. I only know to ways to display the seven stars. The first is to display a png width seven stars, the other is to display seven images of one star. Isnt there some simpler thing to do? Like: $stars = $row['votes'] /// In this example, the votes gives me the number 7 print ("$stars * <img src='star.png width='10px' height='10px' alt=''/>"); Sorry if I sound crazy, but I feel kinda dumb coding 55 times the same thing just for the sake of the stars. Thank you. Link to comment https://forums.phpfreaks.com/topic/223362-2-instead-of-two/ Share on other sites More sharing options...
litebearer Posted January 4, 2011 Share Posted January 4, 2011 Something like... function MyStars($quantity) { $i=0; $display = ""; while($i<$quantity) { $display = $display . "<IMG src ='star.png' width='10' height='10'>"; $i++; } echo $display; } $stars = $row['votes'] /// In this example, the votes gives me the number 7 MyStars($stars); Link to comment https://forums.phpfreaks.com/topic/223362-2-instead-of-two/#findComment-1154625 Share on other sites More sharing options...
Kieran Menor Posted January 4, 2011 Share Posted January 4, 2011 str_repeat() maybe? Link to comment https://forums.phpfreaks.com/topic/223362-2-instead-of-two/#findComment-1154659 Share on other sites More sharing options...
litebearer Posted January 4, 2011 Share Posted January 4, 2011 working example http://nstoia.com/stars.php Link to comment https://forums.phpfreaks.com/topic/223362-2-instead-of-two/#findComment-1154661 Share on other sites More sharing options...
Kieran Menor Posted January 4, 2011 Share Posted January 4, 2011 There is no real point in making your own implementation of a function that can repeat a string when such already exists in PHP. Link to comment https://forums.phpfreaks.com/topic/223362-2-instead-of-two/#findComment-1154662 Share on other sites More sharing options...
soltek Posted January 4, 2011 Author Share Posted January 4, 2011 There is no real point in making your own implementation of a function that can repeat a string when such already exists in PHP. Haha, I knew there had to be a function like that. Thanks, it's perfect. Link to comment https://forums.phpfreaks.com/topic/223362-2-instead-of-two/#findComment-1154674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.