473,687 Members | 3,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking string for multiple values

384 Contributor
I have a string passed in and I want to check validate it to make sure that multiple values don't exist at the start, the below would only check the entire string for the value??
Expand|Select|Wrap|Line Numbers
  1. if(strstr($string,array("value1","value2","value3")) {
  2.   ...
  3. }
Dec 30 '09 #1
4 3025
code green
1,726 Recognized Expert Top Contributor
What do you mean by 'start'?
Dec 30 '09 #2
ziycon
384 Contributor
Say a link is entered like bytes.com I want to check it to see if it has www. before it and if not to add it or another example would be say http://www.bytes.com was entered I want to check and remove the http://.

I'm looking to validate the input so only www.bytes.com is kept.

Does this make sense?
Dec 30 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
it does. it also makes sense to use Regular Expressions for that.
Dec 30 '09 #4
Atli
5,058 Recognized Expert Expert
Hey.

You could use the substr function to fetch parts of the string and see if they are, or are not, what you expect them to be.

Like, to remove http:// from the start of a string:
Expand|Select|Wrap|Line Numbers
  1. if(substr($input, 0, 7) == 'http://') {
  2.     $input = substr($input, 7);
  3. }
Or, as Dormilich suggested, you could use a regular expression. It's a lot more complex, and may be overkill if this is as simple as removing http:// from URLS, but may be better if you are doing something more complex.

For example, this could be used with the preg_match function to split an URL into individual parts, which can then be verified and assembled into the format you want.
Expand|Select|Wrap|Line Numbers
  1. $regexp = '#(https?://)?(([^\.]+\.)+)?([^\.]+)\.([^/]{2,4})#i';
But, like I say, this is a bit more complex, so it may be a bit much for simple tasks that substr can take care of.
Dec 30 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
10017
by: Robert Mark Bram | last post by:
Hi All! I have the following code in an asp page whose language tag is: <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%> // Find request variables. var edition = Request.Form ("edition"); var language = Request.Form ("language"); Response.Write("Edition is type &quot;" + (typeof edition) + "&quot; and value &quot;" + edition + "&quot;<br>");
6
14312
by: Web Developer | last post by:
Hi, I come across the term "type checking" very often in my readings on C++, and have never heard it in Java. Besides the simplistic answer that it checks the "type", what more does it mean? WD
67
4255
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. Unfortunately these ad hominem rhetorts are frequently introduced into purely technical discussions on the feasibility of supporting such functionality in C++. That usually serves to divert the discussion from the technical subject to a discussion of the...
32
14848
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
21
8759
by: jacob navia | last post by:
Many compilers check printf for errors, lcc-win32 too. But there are other functions that would be worth to check, specially memset. Memset is used mainly to clear a memory zone, receiving a pointer to the start, the value (most of the time zero) and the size of the memory array to clear. Problems appear when the size given is not the size of the object given as its first argument. For instance void fn(void)
9
5635
by: D. Shane Fowlkes | last post by:
(ASP.NET 2 / VB) Question - How can I write a If statement to see if a control (textbox) actually exists on a page? Upon page_load, a certain control may or may not be visible on the page so I need to first check to see if it actually exists and then if it does, get the value from it. If I try to read it or check if its "visible" if it's not on the page then of course, it'll error. Thanks!
10
1419
by: Brent | last post by:
I have a list of company names (say, IBM, Corning, General Motors, and another 5,000 of them). If I take a body of text, a news article, for instance, and I want to see which company names appear in that text, is there an efficient way to do this? I thought about looping through the array of names, and doing an IndexOf or Regex match, but this method is slow. Then I thought about an array intersection, but this is problematic for...
7
6856
by: john.cole | last post by:
I have searched all the groups I can, and I still haven't been able to come up the solution I need. I have the following problem. In my form named sbfrmSpoolList, I am entering a job, spool and revision number. My table is indexed properly to not allow duplicates, but I would like teh user to be notified that they are typing a duplicate via a message box, then I woulld the update of the record to be cancelled. I have tried the...
0
9072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8782
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
8786
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...
0
7621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2964
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
2215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.