Solved

PHP function to select first two values of variable

Posted on 2011-03-04
3
301 Views
Last Modified: 2012-05-11
Hello,

i need php function to select first two values of variable.

eg.
 $val=3456;
or  
$val=34567;

then it will pick only first two values
$val=34;


0
Comment
Question by:savsofts
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 35034486
you mean substr:
http://php.net/manual/en/function.substr.php

$val = substr($val, 0,2);

Open in new window

0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35034501
function extractNum($aNumber,$num){
$temp = str_split ($aNumber);

for($i=0;$i<$num;$i++){
$rtn.=$temp[$i];

}
return $rtn;
}

Open in new window

0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35034525
use substr :), assume the logic is similar the in the source
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change password links 7 72
Keep getting 503 on Curl request 6 30
How do I execute a file from within a PHP script with headers already sent? 5 20
html input type 3 21
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now