473,809 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check string rep's integer

Is there a PHP function to verify that a string validly represents an
integer?
Jul 17 '05 #1
7 5486
*** sinister wrote/escribió (Fri, 21 Nov 2003 15:10:16 GMT):
Is there a PHP function to verify that a string validly represents an
integer?


Check is_int() manual page.

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #2
"sinister" <si******@nospa m.invalid> writes:
Is there a PHP function to verify that a string validly represents an
integer?


See the Variable Functions chapter in the PHP manual:

http://www.php.net/manual/en/ref.variables.php

The answer may not be as simple as you'd initially think, so be
sure to read a function's description and user-contributed notes
before using it. Test whatever code you end up writing to make
sure it gives the expected results for both integers and non-integers.

You could also use a regular expression, but using variable functions
would probably make your intentions more clear.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #3

"Alvaro G Vicario" <al************ ******@telecomp uteronline.com> wrote in
message news:1p******** *************** ******@40tude.n et...
*** sinister wrote/escribió (Fri, 21 Nov 2003 15:10:16 GMT):
Is there a PHP function to verify that a string validly represents an
integer?
Check is_int() manual page.


No; that checks whether a variable is an integer, not whether a string
variable corrected represents an integer.

I'm thinking of
"66" true
"00037" true
"afdfdfd" false
"-00218" true
"- 18" false

--
--
-- Álvaro G. Vicario - Burgos, Spain
--

Jul 17 '05 #4

"Michael Fuhr" <mf***@fuhr.org > wrote in message
news:3f******** @omega.dimensio nal.com...
"sinister" <si******@nospa m.invalid> writes:
Is there a PHP function to verify that a string validly represents an
integer?
See the Variable Functions chapter in the PHP manual:

http://www.php.net/manual/en/ref.variables.php


Not sure I understand the connection to variable functions. I would have
thought that I need a function on a string, returning a boolean, and that
either (a) it's already in php, or (b) I'd have to write my own.

I've done (b) in C and C++.
The answer may not be as simple as you'd initially think, so be
sure to read a function's description and user-contributed notes
before using it. Test whatever code you end up writing to make
sure it gives the expected results for both integers and non-integers.

You could also use a regular expression, but using variable functions
would probably make your intentions more clear.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Jul 17 '05 #5
"sinister" <si******@nospa m.invalid> writes:
"Michael Fuhr" <mf***@fuhr.org > wrote in message
news:3f******** @omega.dimensio nal.com...
"sinister" <si******@nospa m.invalid> writes:
Is there a PHP function to verify that a string validly represents an
integer?


See the Variable Functions chapter in the PHP manual:

http://www.php.net/manual/en/ref.variables.php


Not sure I understand the connection to variable functions. I would have
thought that I need a function on a string, returning a boolean, and that
either (a) it's already in php, or (b) I'd have to write my own.


Did you look at the list of functions at the above link? If none
of them seem suitable, could you explain why? As I mentioned in
my first followup, the solution isn't as obvious as it might seem
at first, but it's there if you read the documentation and user
comments.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #6

"Michael Fuhr" <mf***@fuhr.org > wrote in message
news:3f******** **@omega.dimens ional.com...
"sinister" <si******@nospa m.invalid> writes:
"Michael Fuhr" <mf***@fuhr.org > wrote in message
news:3f******** @omega.dimensio nal.com...
"sinister" <si******@nospa m.invalid> writes:

> Is there a PHP function to verify that a string validly represents an > integer?

See the Variable Functions chapter in the PHP manual:

http://www.php.net/manual/en/ref.variables.php
Not sure I understand the connection to variable functions. I would have thought that I need a function on a string, returning a boolean, and that either (a) it's already in php, or (b) I'd have to write my own.


Did you look at the list of functions at the above link? If none
of them seem suitable, could you explain why? As I mentioned in


OK, looking at the page again, I see what you mean. Basically, it's (b)
"I'd have to write my own," but the user comments show how to make it short
and sweet.

Thanks.

Best,

S
my first followup, the solution isn't as obvious as it might seem
at first, but it's there if you read the documentation and user
comments.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Jul 17 '05 #7
*** sinister wrote/escribió (Fri, 21 Nov 2003 20:14:29 GMT):
Check is_int() manual page.


No; that checks whether a variable is an integer, not whether a string
variable corrected represents an integer.


You are right. Probably intval() is a better choice.

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1941
by: Csaba Gabor | last post by:
I wrote a .repeat(n) function for strings which seemed to work fine: String.prototype.repeat = function(n) { // repeats the string n times if (n<1) return ""; if (n<2) return this; for (var aStr = ;--n>0;) aStr.push(aStr); return aStr.join(""); }
5
5486
by: int main(void) | last post by:
Hi all, Following is my attempt to write a string search and replace function. #include <stdio.h> #include <stdlib.h> #include <string.h> /*------------------------------------------------------------------------------------------- | Function name : strrep
1
7431
by: redpayne | last post by:
Okay, I finally got this program to run according to what the book had us build it as. Now prof wants case 2 and case 3 to prompt again for input, check input to see if it is the correct type, then display a "correct" message if is correct. So, If you choose 2 from the original pane, you would be prompted to enter an integer. The program would check to see if you input an integer and if it was then you would get a "correct" message. If not...
2
6696
by: Thall | last post by:
Hey Gurus - I've seen a few solutions to this problem, but none of which I can do without a little help. Here's the situation The following code loops thru a sales report, using the sales rep ID as a filter so that multiple reports are created. This is now generating a PDF report, but I need to change it to RTF documents. My question is, since I can't create an RTF using open report, is there a way to use the strFilter with the OutputTo...
44
10243
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
6
2514
by: temper3243 | last post by:
Hi Can someone explain me what is happening below ? Why is it printing 401380 $ cat scanf.c #include<stdio.h> int main() { int i; scanf(" %d",&i);
6
4777
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I am having trouble with the binding of a check box. I have a form for editing and adding reps. I am using a bindingsource and a bindingnavigator. I have on the form an "Active" checkbox, which is bound to the IsActive field in the bound data table. It works fine for the reps that are already in the table. The problem occurs when I click on the AddNew button on the bindingnavigator. I have the field in the table to default to true,...
11
904
by: Lothar Behrens | last post by:
Hi, I have selected strtok to be used in my string replacement function. But I lost the last token, if there is one. This string would be replaced select "name", "vorname", "userid", "passwort" from "users" order by "users"
5
25531
by: herman | last post by:
How can I replace all occurrences of a character with another character in std string? For example, I want to replace '/' with '+' in my std::string I have looked at the replace() method in the string class, it does not replace all occurrences of a character with another character. http://www.cppreference.com/cppstring/index.html
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.