Jump to content

misterm

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

misterm's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the replies. Think I just figured it out. I just need an array of several pre-defined numbers. Then I want to extract just one of those numbers randomly. <? $randomProductID= array("50","63","82","92","99"); $randomProduct=array_rand($randomProductID,2); echo "Randon number ".$randomProductID[$randomProduct[0]]; ?> This seems to work. Thnaks again for the replies MrM
  2. Hi I have been pulling my hair out over this. I am trying to randomly display an include file within a php web page. Each include has a number as it's name i.e. 15.php 17.php etc. becuase these files aren't numbered 1 to 100 for example, I only need to show a select few at random, so my list may be 7.php 9.php 12.php 22.php etc. I tried adapting the script at: http://www.pixel2life.com/publish/tutorials/904/php_random_content_or_advertisment/ and then <? include ($myRandomNumber.'.php'); ?> but I can't seem to get it to work and this seems a really clumbsy way of doing this. I tried selecting a number from an array, but couldn't get that to work either :/ If anyone has a better suggestion, it would be greatly appreciated. Many thanks Mr M
  3. Brilliant! Thank you. You've saved me a real headache there. Drop me a line if you ever need a monster drawing D
  4. Thanks inversesoft123 The second option you posted works great when $myString has 2 characters before the ".", but when there is only 1, it still shows 3 chcaracters after the ".": so a string with the value of 17.4942 is displayed as 17.49 But when it it's value is 7.4942, it is displayed as 7.494 and not 7.49 :/ Thanks again D
  5. Hi I am trying to trim the last 2 chracters of a sting that follow "." So for example 45.4545 will become 45.45. I need this to work too if the string starts with any number of characters before the ".". eg 4.4545 or 445.4545 I tried using $myString = substr ($myString, 0,-2); which will give me 45.45 but which will not work if my string has only 1 character before the "." (which would give 5.454). to recap: I only want 2 characters to appear after the "." no matter how many characters appear before the ".". Any help would be much appreciated Many thanks D So If I have a string containing 44.4567 I want to trim to just 44.45, which I can do with But this won't work if my string is 4.4567 But what I need to do really is trim whatever appeas after the "." by 2 characters so if my string is just
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.