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?? - if(strstr($string,array("value1","value2","value3")) {
-
...
-
}
4 3021 code green 1,726
Recognized Expert Top Contributor
What do you mean by 'start'?
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?
Dormilich 8,658
Recognized Expert Moderator Expert
it does. it also makes sense to use Regular Expressions for that.
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: - if(substr($input, 0, 7) == 'http://') {
-
$input = substr($input, 7);
-
}
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. - $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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 "" + (typeof edition) + "" and
value "" + edition + ""<br>");
|
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
|
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...
|
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) ||
|
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)
| |
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!
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |