Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP function to select first two values of variable

Posted on 2011-03-04
3
303 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 143

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

839 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