This question already has answers here:
How to check if page url has www in it or not with PHP?
(6 answers)
Closed 8 years ago.
I am creating a frontend form in WordPress where I am using a simple HTML textbox to input a web url. Now I want to check if the value entered is a URL and not just any random text. Anyway to do that?
if (str[i] == 'w' && str[i+1] == 'w' && str[i+2] == 'w' && str[i+3] == '.')
return (1);
Related
This question already has answers here:
regex preg_match for digit in middle for a string
(3 answers)
Closed 3 years ago.
This is what I am currently using to check the incoming get request
if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'GET' && strpos($_SERVER['REQUEST_URI'], 'api/rooms/1/messages') !== false) {
}
as you can see the rooms number is hardcoded I only need to check if it is a number at all on that specific spot between rooms/ and /messages how can I achieve this
You could probably use preg_match.
Instead of doing:
strpos($_SERVER['REQUEST_URI'], 'api/rooms/1/messages') !== false
You could do:
preg_match("/api\/rooms\/[0-9]+\/messages/", $_SERVER['REQUEST_URI'])
This question already has answers here:
Check if multiple strings are empty [duplicate]
(7 answers)
Closed 5 years ago.
I have more than 30 fields in a form, and can't believe that I must write an array to check if any of them is empty (likehere)
I need something like js
$_POST[].each function{
if this is empty...
}
and hope that 'php' as so glorified language has something like this or similar.
Try this:
foreach($_POST as $post)
{
if( !empty($post) )
{
// your code here
}
}
This question already has answers here:
URL rewriting with PHP
(5 answers)
Closed 5 years ago.
I'm looking for a way to turn variables in a URL after the question mark into a simple notation with a slash.
For example: I would like to make it possible to enter this link:
http://localhost/MySite/View?Name=Test
in this form into the browser
http://localhost/MySite/View/Test
The MySite then should recognize "Test" as the Name variable. So basically the two links should give the same result.
How it will be done ?
You should read your request uri and search for the third subdirectory:
$view = $_GET['Name'];
if(!isset($view) && isset($_SERVER["REQUEST_URI"])) {
$uriArray = explode($_SERVER["REQUEST_URI"]);
if(count($uriArray) == 3 && $uriArray[1] == 'View') {
$view = $uriArray[2];
}
}
This question already has answers here:
The 3 different equals
(5 answers)
Closed 6 years ago.
So I'm making an attempt to remove links from the database, both image path and video link. I have given each type of file a code, 5 for videos, 2 and 1 for images. I have the following if statement to account for it:
if($mCode = 2 || $mCode = 1){
unlink($mLoc); // delete image from directory
}
For my video link, however, which has an mCode of 5, whenever i try to remove it, it removes the file, but I get this warning:
Warning: unlink(test): No such file or directory
Why is it still passing through the if statement? Or how could I prevent this?
With a single = you will set the $mCode.
Use == for loose validation
Use === for strict validation (includes the datatype validation)
if($mCode == 2 || $mCode == 1){
unlink($mLoc); // delete image from directory
}
This question already has answers here:
How do i make shortcuts for IF statements?
(5 answers)
Closed 8 years ago.
I have a function that checks user permissions and I want it to do this:
if(verify("O") || ("M"))
so that it checks if the user has the permission "O" or "M" but it does not work
You're close. This should work:
if(verify("O") || verify("M"))
If your function verify() only accepts one input. You need to call it again with the second input. Now, if either verify("O") or verify("M") returns true, your IF statement will return true.