Solved

PHP function to select first two values of variable

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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

19 Experts available now in Live!

Get 1:1 Help Now