Jul 6, 2008

Determining Whether A Phrase Is In A Variable - deciding whether a string is a url

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Determining Whether A Phrase Is In A Variable - deciding whether a string is a url

electriic ink
I have a input box in a form called "button" and when the user clicks Submit! I want php to determine whether or not this is a url or just text.

All urls have "http://" in them so I have decided I need a script which can determine whether or not "http://" is in a variable or a string. The problem with using strings is that I've never needed to use them before (and thus have no knowledge about them).

When I was using asp, I knew there was a function called instr() but I can't find php's equivalent. Does anybody know?

Thanks in advance!

Reply

truefusion
Here, use something i came up with for my old website.

CODE

$name = $_POST['name'];
$site = $_POST['site'];

if(!$name || !$site)
{
echo "You did not fill out the entire form.";
exit;
}
else if($name && $site && (!ereg("^http://", $site) && (!ereg(".com$", $site) xor !ereg(".org$", $site) xor !ereg(".net$", $site))))
{
echo "You did not enter http:// and one of the following domain extensions: .com, .net, .org; in the url.";
exit;
}
else if($name && $site && (ereg("^http://", $site) && (!ereg(".com$", $site) xor !ereg(".org$", $site) xor !ereg(".net$", $site))))
{
echo "You did not enter one of the following domain extensions: .com, .net, .org; in the url.";
exit;
}
else if($name && $site && (!ereg("^http://", $site) && (ereg(".com$", $site) xor ereg(".org$", $site) xor ereg(".net$", $site))))
{
echo "You did not enter http:// in the url.";
exit;
}
else if($name && $site && (ereg("^http://", $site) && (ereg(".com$", $site) xor ereg(".org$", $site) xor ereg(".net$", $site))))
{
[insert coding here]
}

 

 

 


Reply

electriic ink
Thanks for the code truefusion. Your help is much apprecaited smile.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : determining, phrase, variable, deciding, string, url

  1. Unexpected T_string In User.php [resolved]
    (5)
  2. Unexpected T_variable...
    Help! (3)
    I did construct the database connection file which is called "config.php". But, I got some mistake
    that has to be solved to continue with working. This is the code itself: //Set the database
    values $confg ="alex1985_admin" //Your database username $confg ="" //Your database
    user's password $confg ="localhost" //Your host $confg ="books" //Your database name
    //Create the function to log into the DB function db_login() { global $confg; $link =
    @mysql_connect($confg , $confg , $confg ) or die("Error connecting: " . mysql....
  3. User Permission Function [php]
    Determining User Permissions (3)
    There have been several recent request for methods to restrict access to various pages on a web-site
    based on User Permissions in sites that have a Login System in place. Here is some code showing one
    method to restrict access by providing a sub-set of your site's links based on the User's
    permissions. In this demonstration, I have defined a string for each 'level of user'
    determining which set(s) of links they can view on your site. Normal MySql procedure would be to
    read the User's permission level from a record in the database. For the purpose of ....
  4. Script Help Required: Undefined Variable
    A fault I cannot spot in PHP (3)
    Hi, when running a PHP script I keep getting the error: QUOTE Notice: Undefined variable: bret
    in c:\program files\easyphp1-8\home\poll.php on line 294 Notice: Undefined
    variable: bret in c:\program files\easyphp1-8\home\poll.php on line 294 (And,
    yes, I get it twice). The code related to the variable is as follows: CODE function
    LogString($string,$type)     {         $t_log = "\n";
            $t_log .=
    $this->globaldata->server_vars['REMOTE_ADDR']."....
  5. Adding String To Integer?
    (1)
    Create a PHP program with the following requirements  Create a program that does the following: 
    creates a variable called “test” (remember the dollar sign)  stores the number 35 to
    test and prints the result  adds 10.0000 to test and prints the result  subtracts 5.123123 from
    test and prints it out  stores the character string “happy to be here” to test and
    prints  adds 10.0000 to the variable test (try to guess what will happen) whats the solution to
    this problem? any help would be appreciated.....
  6. Php Variable Basics
    Where would PHP programmers be without the variable? Learn all about t (9)
    CODE <?php $var= "This is a variable"; echo $var; ?> Outcome This is
    a variable Using what we know about the echo function, we can see that we have created a
    variable, and then used the echo command to display it. This is fairly simple, and can have many
    uses, but there is much more too it! CODE <?php $var1 = "This is variable
    one"; $var2 = "This is variable two"; $varall = "$var1. $var2.
    You just combined three variables in one!"; echo $varall; ?> Outcome This is....
  7. Php Echo
    Learn what the echo can do for you. Includes basic echo and variable p (10)
    PHP Echo Description The echo() command has one purpose, displaying whatever you put in between the
    brackets. Learn to use it to your advantage. Try It Out There is your echo command. For now,
    it does nothing. It has no value to display. Outcome This is my text. Now this echo command
    has a value to display. Whatever you replace "This is my text." with will be displayed. Alright,
    lets move onto the next step. This time, we will include a variable in the echo command.
    $var = "This is a variable"; echo "$var. Congratualations, you just parsed a....
  8. Data Structures -- String -- Arrange Based On Repetition
    String data structure (1)
    Consider a string with any number of elements occurring any number of time. Rearrange the string
    in such a way that the alphabet with most occurrence occurs in the followed by the next most
    occurring alphabet and so on... It should also be seen that the alphabets should occur frequency
    number of times. Example: Input : abcdaeghzabcdbhb Output : bbbbaaaccddhhegz ....
  9. Data Structures -- String -- Palindrome
    Check if a string is a palindrome... (4)
    Write an algorithm to check whether a given string is palindrome or not in time complexity O(n)
    What is a palindrome?? QUOTE A palindrome is a word, phrase, number or other sequence of units
    that has the property of reading the same in either direction (the adjustment of punctuation and
    spaces between words is generally permitted). Composing literature in palindromes is an example of
    constrained writing. The word "palindrome" was coined from Greek roots palin
    (πάλιν; "back") and dromos (δρóμος; "way,
    direction") by....
  10. Getting An Array Value Of A Dynamic Variable
    (9)
    Ok i can't believe I need help in php but I can't figure this out... If i have an array,
    lets say called test, how do i get a certain value from that array when referencing it dynamically
    by either a string or another variable? Example: CODE $test=array(1,2,5);
    $name="test"; //Doesn't work: echo $$name[0]; /Doesn't
    work: echo ${$name}[0]; ....
  11. T_string Error Please Assist
    (5)
    I have unexpected t_strings in 3 lines they are CODE <?php // $Header$ //this
    script may only be included - so its better to die if called directly. if
    (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !==
    false) {   header("location: index.php");   exit; } /* A basic library to
    handle a cache of some Tiki Objects, usage is simple and feel free to improve it */ class Cachelib
    {   var $folder;   function Cachelib() {         global $tikidomain;
            $th....
  12. <?php ?> Sloppy Login Script
    Sloppy login script, couse i used @ on one string (12)
    Here's a sloppy 3 files login script. First file is Login file that looks like this login.php
    CODE <form action="check.php" method="post"> Username: <input
    type="text" name="username1"><br /> Password: <input
    type="password" name="password1"><br /> <input type="submit"
    value="Login"> </form> Basicly that is HTML form that's used for input
    Second part of the script is the check.php that we call from our login.php form QUOTE ....
  13. I Need To Get This Off My Chest Before I Explode
    Not really, but it's a marketing phrase (4)
    I remember reading this thing back when I was really young, about a special offer on a web site that
    promised to send millions of visitors to your own web page. It was a scam, but I was young enough to
    waste time reading about it. Anyway, the passage I remember in the sales pitch was "let me get this
    off my chest before I explode" or something like that. So I searched google for the phrase, and man,
    it must be really effective and really popular because every random scam or shady business site you
    can think of uses it. They might spam message boards with a sales pitch an....
  14. Help Php: How To Load String From Text File (solved)
    Loading string from text file when you click on your link (9)
    I learned the way to load other files with the code posted on this forum. Now i wanted to try
    something for my side menu. I am calling this a string, --> $tekst , maybe it's
    called something else i'm not sure Now let's say i have a file called details.txt In that
    file i would like to have something like this $detailsaboutphp1 = ("details details details
    1"); $detailsaboutphp2 = ("details details details and even more details 2"); How to make a
    code that loads those $strings on click of a mouse. When we tried to load extern....
  15. Incrementing Mysql Integer
    int comes out as string? (7)
    I am attempting to perform mathematical operations on a number extracted from a MySQL database. The
    integer is stored as an integer in the database, and nothing I am doing to it in the PHP script
    would transform it into a floating-point value. I don't even want to worry about sticking it
    back in just yet: CODE // the value I want to increase here is logins... $query1 =
    "SELECT * FROM users WHERE id='$id'"; $result1 =
    mysql_query($query1) or die(mysql_error()); $row1 =
    mysql_fetch_array($....
  16. String Theory And The Ten Dimensions Of The Universe
    Advanced physics theories (10)
    String Theory and the Ten Dimensions of The Universe Recently I have found out about string
    theory. Most of the people on earth only knows that there only exist three dimensions(width, length,
    and height) and a fourth dimension which is the difference of a matter from one time point to
    another. And according to String Theory there exists six more spatial dimensions that are uknown or
    unnoticeable by a person. Basically, String Theory uses vibrating strings with a planck length,
    10^-35m, as a fundamental element of the universal not points. With this, physicists are a....
  17. Linux Or Windows? Help!
    Need help on deciding which is best for an old laptop for girlfriend (16)
    My girlfriend and her sister just got this laptop because their parents bought a new one. They are
    going to use it to do homework, messenger and look up the internet. They gave it to me so that I can
    fix it because it has windows 98 and it is really slow. If I would like to install windows xp on it
    I would have to get another 64 megs of ram, otherwise it would be running on lower than recommended
    but still accepted by xp. I then thought about using Linux, but right now there are so many
    distributions that I dont know which one I should try, and even if I should try it. ....
  18. String/text Formatting?
    (4)
    right i was wondering if someone could help me with this: I notice on this site if i make a topic
    for example WAppY rOCks WaP, it will come out like Wappy Rocks Wap. I also want to do this to my
    forums, can anyone give me the code to format a string of text in this way? THANKS IN ADVANCE ....
  19. Mysql For Vb.net
    Connection String (2)
    Put it simply, how could I connect MySQL into VB.NET? I use SQLConnection component, but it search
    only MS SQL servers. Please help... thanks in advance....
  20. Insert String To Mysql
    Important!!! (5)
    Hi everyone!

    I have completed the
    MySQL Table creation. but now I have a little larger problem /tongue.gif"
    style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" />
    ....
  21. Javascript Help
    Can't do simple variable functions ¬_¬ (1)
    Edit: Haha, nevermind....I've had it fixed now /biggrin.gif" style="vertical-align:middle"
    emoid=":D" border="0" alt="biggrin.gif" /> an admin/mod can delete this if s/he feels like it
    /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> Slide show
    So i'm trying to make my own slideshow, see above. I have the pictures showing depending what
    "num" equals...Well, the code's here: CODE <script TYPE="text/javascript">
    <!-- var num = 1; var pic = "pic.gif"; switch (num) { default&....
  22. Java String Overview
    (2)
    QUOTE String Overview Strings are sequences of Unicode characters. In many programming
    languages strings are are stored in arrays of characters. However, in Java strings are a separate
    object type, String. The "+" operator is used for concatenation, but all other operations on strings
    are done with methods in the String class. See the Summary - Strings for an overview of the methods
    in String and related classes. Related types and classes String The basic class for strings. String
    objects can NOT be changed. char Primitive type for 16-bit Unicode characters. Char....
  23. Not Allowing Symbols In A String
    (3)
    I was looking for a quick solution so i could check a string for any symbols and stuff (basically
    anything that isnt numbers and letters) in it. One of the first google searches that came up were
    for a forum called "sitepoint". The thread was talking about the same thing I was trying to do.
    This was their solution: CODE if (ereg("[a-zA-Z0-9]+",
    $username)) {    echo 'OK.'; } else {    echo 'Invalid characters.';
    } So i tried it out. Didn't work. I played with the code and i still couldn't get....
  24. File String Delete?
    (2)
    Say i have a file file.txt... Can someone give me an example of how to delete a string from this
    file ie.. The file contains: wappy::sucks::at::php --- i want to delete sucks::....
  25. String Search Outside My Site?
    Help me work this out please ;-) (2)
    Hi ;-), i need some php code that will search any site or index page for a string. So i can check if
    my link is on sites it should be quickly?....
  26. Various String Functions In C
    (5)
    Hi, i read a lot of forum in which people want to learn C. Well i am giving this tutorial for all
    those who want to use strings. All the information provided is written by me and has not been copied
    from anywhere Well First of all lets see how to store a string into a string. First of all you
    need to initiate a variable which can hold an array of characters. It is necessary to initiate an
    array of characters rather than just a character: for example: CODE char string; is
    incorrect because if you store a string rather than a character in it, you cannot acces....
  27. Php Form Help!
    Parse error T_LNUMBER - expecting T_VARIABLE (3)
    Hello, I am trying to make an employee application. I was just wondering if anyone knows how to spot
    a php code error, when the code directly around the line with the error looks the same. below is
    some of my process.php code. I beleive the error is on line 41. QUOTE PHP parse error: PHP
    Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in
    /home/wwwange/public_html/FORMS/forms/process.php on line 41 Process.php code: CODE
    <?php include("global.inc.php"); $errors=0; $error="The foll....
  28. Variable Definition
    (6)
    I am creating a checkbook balancing program that uses multiple forms. The first form will allow the
    user to enter a certain number of deposits, withdrawals, etc. I want to have the ability to have the
    user be able to enter more than what this first screen will provide by allowing them to transfer to
    another form. I would like to store the data entered for each of these transaction types into a
    global variable (to be used throughout the project) array, and produce a total of the dollar amount
    of this transaction type to be used in coming up with an ending balance of the a....
  29. The "lol" Phrase
    (53)
    This phrase bugs me. I don't like it when people on Instant Messengers type LOL (which means
    laugh out loud) but don't actually laugh out loud. I do it too because it is a annoying habbit
    which I got off of practically everyone I talk to on MSN. So, I decided to make the phrase "sl" uop
    which means seriously laughing. Now if you ever seriously laugh in a conversation then remember this
    thread and type sl instead of lol. /smile.gif' border='0' style='vertical-align:middle'
    alt='smile.gif' /> ....
  30. What Is A T_string?
    Please help! I'm new at PHP Programming (13)
    I'm new at PHP, and I looked for a while on here, and found some stuff I was looking for about
    form processing, and sending E-Mail through PHP. However, the script I just created won't work.
    I get the following error: Parse error: parse error, unexpected T_STRING in
    /home/hamtaro/public_html/send_feedback.php on line 9 Exactly what is a T_STRING? If I need to post
    my code, I will.....

    1. Looking for determining, phrase, variable, deciding, string, url

Searching Video's for determining, phrase, variable, deciding, string, url
Similar
Unexpected
T_string In
User.php
[resolved]
Unexpected
T_variable..
. -
Help!
User
Permission
Function
[php] -
Determining
User
Permissions
Script Help
Required:
Undefined
Variable - A
fault I
cannot spot
in PHP
Adding
String To
Integer?
Php Variable
Basics -
Where would
PHP
programmers
be without
the
variable?
Learn all
about t
Php Echo -
Learn what
the echo can
do for you.
Includes
basic echo
and variable
p
Data
Structures
-- String --
Arrange
Based On
Repetition -
String data
structure
Data
Structures
-- String --
Palindrome -
Check if a
string is a
palindrome..
.
Getting An
Array Value
Of A Dynamic
Variable
T_string
Error
Please
Assist
<?php
?> Sloppy
Login Script
- Sloppy
login
script,
couse i used
@ on one
string
I Need To
Get This Off
My Chest
Before I
Explode -
Not really,
but it's
a marketing
phrase
Help Php:
How To Load
String From
Text File
(solved) -
Loading
string from
text file
when you
click on
your link
Incrementing
Mysql
Integer -
int comes
out as
string?
String
Theory And
The Ten
Dimensions
Of The
Universe -
Advanced
physics
theories
Linux Or
Windows?
Help! -
Need help on
deciding
which is
best for an
old laptop
for
girlfriend
String/text
Formatting?
Mysql For
Vb.net -
Connection
String
Insert
String To
Mysql -
Important
3;!!
Javascript
Help -
Can't do
simple
variable
functions
¬_¬
Java String
Overview
Not Allowing
Symbols In A
String
File String
Delete?
String
Search
Outside My
Site? - Help
me work this
out please
;-)
Various
String
Functions In
C
Php Form
Help! -
Parse error
T_LNUMBER -
expecting
T_VARIABLE
Variable
Definition
The
"lol&qu
ot; Phrase
What Is A
T_string? -
Please
help!
I'm new
at PHP
Programming
advertisement



Determining Whether A Phrase Is In A Variable - deciding whether a string is a url



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE