logo
down
shadow

How to check the URL's structure using PHP preg_match?


How to check the URL's structure using PHP preg_match?

By : user3100304
Date : January 12 2021, 01:40 AM
I hope this helps . If section is a word (and can not contain digits), and item is a number, you could match word characters except digits using [^\W\d]+ and \d+ to match 1+ digits.
As in the example data there are optional parts, you could replace (/.*)?$ with (?:/[^\W\d]+(?:/\d+)?)?$.
code :
^https?://[a-z0-9-]+(?:\.[a-z0-9-]+)*(?::[0-9]+)?(?:/[^\W\d]+(?:/\d+)?)?$


Share : facebook icon twitter icon
php preg_match multiple urls

php preg_match multiple urls


By : Papagrape21
Date : March 29 2020, 07:55 AM
seems to work fine I know next to nothing about php so this will make someone laugh probably.
code :
// [12] to match 1 or 2
// also need to escape . for match real . otherwise . will match any char
if (!preg_match("/site[12]\.net\.nz/",$host)) {
    header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}
if (!preg_match("/site1\.net\.nz|site2\.net\.nz/",$host)) {
    header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}
Check text area for URLs with preg_match

Check text area for URLs with preg_match


By : Kenterky
Date : March 29 2020, 07:55 AM
I wish this helpful for you i found this code for checking a text area: , you just need to add / like
code :
  preg_match("/(www.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9.]+)/",$textp)
preg_match() to check Image urls without [img] BB tags and return boolean value using PHP

preg_match() to check Image urls without [img] BB tags and return boolean value using PHP


By : user2120072
Date : March 29 2020, 07:55 AM
I wish this helpful for you With regex is quite difficult to look for a pattern without a piece, in this case the img open and closure tag.
So I would search the urls within the tag, then search all the urls and compare these counts
code :
$text = "";

$tagPattern = "/\[img\].+?\[\/img\]/";
preg_match_all($pattern, $text, $tagMatches);

$urlInTagCount = count($tagMatches[0]);

$plainPattern = "~https?://\S+\.(?:jpe?g|gif|png)(?:\?\S*)?(?=\s|$|\pP)~i";
preg_match_all($pattern, $text, $plainMatches);

$allUrlCount = count($plainMatches[0]);

return $allUrlCount > $urlInTagCount;
preg_match to check if string has specific structure

preg_match to check if string has specific structure


By : Pam B
Date : March 29 2020, 07:55 AM
this one helps. Assuming only the restrictions listed in your question are needed, this will validate the string:
code :
$number = 3;
$regex = sprintf('/^[^:]+:(?:[^;]+;){%d}$/', $number);

if (preg_match($regex, $string)) {
    echo "It matches!";
} else {
    echo "It doesn't match!";
}
php > $number = 3;
php > $regex = sprintf('/^[^:]+:(?:[^;]+;){%d}$/', $number);

php > if (preg_match($regex, 'options:blue;white;yellow;')) {
php {     echo "It matches!";
php { } else {
php {     echo "It doesn't match!";
php { }
It matches!

php > if (preg_match($regex, 'options:blue;white;yellow;green;')) {
php {     echo "It matches!";
php { } else {
php {     echo "It doesn't match!";
php { }
It doesn't match!
/.../          Start and end of the pattern.
^              Start of the string.
[^:]+          At least one character that is not a ':'.
:              A literal ':'.
(?:[^;]+;){N}  Exactly N occurrences of:
                   [^;]+  At least one character that is not a ';'.
                   ;      A literal ';'.
$              End of the string.
Preg_match urls in css

Preg_match urls in css


By : user2628638
Date : March 29 2020, 07:55 AM
around this issue For your example data, one option could be to recurse the first subpattern (?1 and use a second capturing group for the url.
The url will be in capturing group 2.
code :
url(\(((?:[^()]+|(?1))+)\))
$re = '/url(\(((?:[^()]+|(?1))+)\))/m';
$str = 'background:url("/product/header/img1.png") and background:url("/product/header/img2.png\' and background:url(/product/header/img3.png"))';

preg_match_all($re, $str, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
    if (preg_match('/^([\'"]?)[^"]+\1$/', $match[2])) {
        echo trim($match[2], "'\"") . PHP_EOL;
    }
}
/product/header/img1.png
Related Posts Related Posts :
  • How to search a row that has been joined with another table
  • How to do mysql LEFT JOIN for Google multiple line chart (php, mysql)?
  • Find the two longest strings separated by dash in PHP
  • Cannot access private property with Set method in Symfony
  • How to compare 2 array of PHP objects then fill in empty string if data not match?
  • strtotime gives back false result to strings in an array
  • How to create Url that contain name and id laravel
  • Codeigniter: Models not working with an error: Undefined property: CI_Loader
  • How to use + or - operators as parameters in Doctrine prepared SQL statement?
  • PHP unpack overlfow variable memory limit
  • PHP preg_replace - text will not be recognized
  • Show image from other domain without showing the domain name - PHP
  • How to run and watch local server at the same time?
  • Access form request from Observer laravel
  • single quote problem with preg_replace_callback
  • How to Create A Unique URL for each product enquiry form for Google Analytics Tracking
  • Laravel email configuration: what am I missing?
  • Assign indexed array values to multidimensional array?
  • Custom WordPress stylesheet not loading
  • Data attribute only returning first value
  • How to list all roles with Permissions,in spatie permission Package?
  • How to achieve this number pattern with n input
  • How to iterate array inside array data in laravel ,output are given below
  • To get output of movie with its genre
  • Extracting some data from a JS object literal string in PHP using Regex
  • axios and vuex are deleting wrong index in array
  • Setting empty CURLOPT_POSTFIELDS
  • Laravel 5.8 use subdomain as API endpoint beside domain.com/api
  • Error while add data in database SQL Server 2016
  • Does PhpStorm allow to skip PHPDoc tags when type hints is declared?
  • html classes are changed to Attributes
  • Using json to import multidimensional data
  • passing data from the view to the controller, where the data comes from another controller
  • How to extract integer and decimal numbers in PHP string correctly?
  • Parsing Sub-Object from an XML Feed with objects
  • Getting error "Unknown column 'text' in 'field list'"
  • How to properly get onedrive access token via php and curl
  • How to add spell check to a php function
  • Is it posible to create css rules with php?
  • Pretty URL with $_GET method
  • Wordpress always load same page - index.php
  • Find value in array and return with new from different array
  • PHP multiple file upload with different keys
  • Can't modify times one a time without weird errors
  • Get size of scraped image with domcrawler (Goutte)
  • Laravel - Ordering a collection of models
  • PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on boolean
  • Strict Standards: Only variables should be passed by reference in /main_dir/sub_dir/backup.php
  • Uncaught Google_Exception: (update) unknown parameter: 'copyRequiresWriterPermission'
  • Laravel 5 form does not redirect with old input
  • How to get values greater than or equal to in Mysql database sql when its a value like 1:00 PM?
  • PHP datediff overday issue
  • Masking an auto incrementing primary key
  • How to grab a String BEFORE a certain word
  • ZF2 Routing Multiple Controllers based on route constraints
  • How to deregister/dequeue jquery.sticky.js in Elementor (Pro)?
  • How to fix errors counting words in text plain with PHP?
  • How to get View data in Laravel in custom helper or directive
  • Creating a new data entry into a database with eloquent and trying to access the variable in the url
  • How to test authentication using Laravel Dusk?
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org