Jump to content


Photo

ereg ??? how


  • Please log in to reply
7 replies to this topic

#1 maumesh

maumesh
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 September 2006 - 08:13 AM

hey frens i am reallly in trouble



i have some numbers
like 1231.23,254.34,21.2      and so on  .........

now i need a php program that will give the output like

1> 1000
      200
        30
          1
and  23  after the decimal

2> 200
      50
        4

and 34 after the decimal


and so onnnn




plz help me fasttttttttttttttttttttttttt





#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 September 2006 - 08:18 AM

What part are you stuck on? Were not here to write code for you, we help people when there stuck.

Post your code.

#3 maumesh

maumesh
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 September 2006 - 08:26 AM

<?php

$value=$_POST['value'];
echo "$value<br>";

if (ereg ("([0-9]{1}[0-9]{1}[0-9]{1}[0-9]{1})", $value, $regs)) {
  echo "$regs[1]";
} else {
  echo "failure";
}



?>

this code really doen't work at alll  i knowww

plz help me out



#4 maumesh

maumesh
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 September 2006 - 09:33 AM

okkkkkk

can u do atleast one favor


can u help me out to get the string before the "."  in the number  32.54

i.e to get only 32

<?php
  $no = '32.54';
  $no1 = stristr($no, '.');
  echo $no1;
// outputs .54
?>


but i need to print 32

help on this mannnn

#5 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 22 September 2006 - 09:35 AM

use the floor() function.

#6 maumesh

maumesh
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 September 2006 - 10:01 AM

$value=231.25;
//echo "$value<br>";
$a=floor($value); 
echo $a;// 231


now i want to put the output in the array

as a(0)=1
    a(1)=3
      a(2)=2

how to do that



#7 maumesh

maumesh
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 September 2006 - 10:02 AM

$no=123;

now how to store 123 in the different variable;



#8 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 22 September 2006 - 10:06 AM

there are a number of different ways to do that you can either split it by a string part 1 in 1 2 in the other etc. or you can use an array function perhaps to split it. Rather than me go through all of that here you should download the manual in chm format here: http://www.php.net/download-docs.php and then look up string functions. You need the str_pos fuction along with the strlen and the trim fuction if you going to go the string route or lookup array functions. Sorry I don't have time to go through all of this this morning, however you should find all this information now I have given you pointers in the php manual.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users