5,358 questions
-5
votes
1
answer
96
views
PHP search for string in $variable and extract the next x characters [closed]
I need to extract the cookie time from a cookie when a user visits the page. The cookie text will be stored in a variable. I'm pretty sure I can do this with preg_match or maybe strpos but I'm not ...
1
vote
1
answer
46
views
php preg_match finding string between two patters
I have this string:
1 x red 1 x blue 3 x yellow
and I want to turn it into:
1 x red
1 x blue
3 x yellow
How can I do this please? I have tried using php preg_match but no luck
$description = "1 ...
0
votes
0
answers
100
views
Regular expression to identify CSS functions
I have a variable called $value that contains a string with a css expression. It can be a value or a function:
rgb( 25, 128, 128 );, transform( -50% -50% );, bottom 50px right 100px;, #198080;, bold;, ...
1
vote
0
answers
90
views
Trying to match any set of elements with a regex that have or whitespace [duplicate]
So I am currently using this regex, but I see a flaw in it for p and div tags:
(<(p?|div?)>).+(\s| )+(<\/(p?|div?)>)+
Given the current string:
<div class="blahblahblah ...
0
votes
2
answers
57
views
Match a number representing weight and its measurement unit
I have a bunch of values representing weight... Some of them are ambiguous, like combining weight and external dimensions of the package, and some don't contain the measurement unit. What I want is to ...
0
votes
0
answers
27
views
preg_replace: get keys from short tags [field id="key"] and replace them with values [duplicate]
I have to determine all short tags like [field id="key1"] in the string, get the keys from the short tags to use them to get the values like $fields["key1"], then replace in the ...
1
vote
1
answer
416
views
Skip Lazy Loading by Image Class Added to Figure Element in WordPress
This is how images are output in WordPress:
<figure class="no-lazy"><img loading="lazy" class="wp-image-12345" src="apple.jpg" alt="apple">...
1
vote
0
answers
75
views
Trying to use preg_match for single word or no spaces, to combat spam
I have a form I continue to build on, so that I can keep spam from being sent through. So far, pretty good - in that the only thing now still getting through are single groups of random letters. I ...
0
votes
1
answer
75
views
Changing from file_get_contents to curl
I've been using file_get_contents in php until the last month when it's stopped working. So I've tried using curl but I'm now getting errors when I extract data from the downloaded webpage (finance....
0
votes
1
answer
52
views
how can I use preg match to match several strings?
I wrote a preg_match to block spam in my form comments that works fine (this blocks web page URL insertion and 2 phrases, and throws a message, which also stops the send.):
$error_message = "&...
2
votes
2
answers
89
views
PHP - Issue matching in string with preg_match
I have a string that contains a list of comma separated values.
eg:
$sitelist = 'SC001rug,SC002nw,SC003nrge';
I'm using preg_match to check if a site is in this string and then return the characters ...
-1
votes
1
answer
81
views
Detect any unwanted characters and number of lines in a file using PHP
I have a problem I can't resolve. And I can't have any feedback since I can only run the script directly on a server, without any possible debug.
My files are transfered through FTP to a server and I ...
0
votes
3
answers
176
views
PHP allow all accented characters in person name, but don't allow Chinese/Russian characters
I am having issues with allowing all English/Latin based characters (including accents), but disallowing Chinese/Russian characters.
The first version I had was as follows:
strlen($values['person_name'...
0
votes
1
answer
55
views
How do I use preg_match() to extract words marked with ## from a string and then put them in html tag(s)?
How to get from here:
The #quick# brown fox jumps over the #lazy# dog
to here:
The span-tag quick /span-tag brown fox jumps over the span-tag lazy /span-tag dog
?
And sometimes it`s only:
The quick ...
0
votes
1
answer
151
views
PHP preg_match page/1 in URL to redirect main URL with RegEx rules
I am creating php pagination and I want to matching the /page/1 in URL "/product-category/womens-jackets/page/1" If the /page/1 in matched then redirect it to the main URL "/product-...
1
vote
1
answer
72
views
preg_match input validation exemption
I have a preg_match function and I want to block 'MT', but allow 'PMT'.
How would I amend this to work as it's picking up the MT in PMT at the moment?
Thanks!
function wppbc_custom_input_validation($...
0
votes
1
answer
69
views
Implementing a PHP Router with Optional Parameters
I've been working on implementing a simple PHP router and have managed to make it work with required parameters. However, I'm struggling to implement optional parameters but I failed. I'll provide the ...
1
vote
2
answers
65
views
How do I regex just the title out?
Sample text:
1. Medium Size +CA $33.00
2. Small Size -CA $4.00
I would like the result to be just 'Medium Size' or 'Small Size' using preg_match
So the regex should detect the '-' or '+' sign and ...
1
vote
1
answer
42
views
How to capture repeating information with regex
I try to capture all information in a string but only the last one is captured.
I start with regex and i need some help.
The string :
correspondent à l'ASIN B00WU8XXXX, mais les attributs suivants ...
1
vote
1
answer
35
views
How to get first preg match elements
I need with preg_match_all() to extract all [ANY_TEXT-pb] blocks.
My code:
$content = 'START Text1 [news-block] text2 [title1-pb] text3 text4 [title2-pb] text5 END';
preg_match_all('/\[(.*?)pb\]/si', $...
0
votes
1
answer
46
views
How to Extract data from html to PHP Array using preg_match or other method
I have html page from old website that has list of some places using below format.
<p><b>Ado’s Kitchen & Bar </b>1143 13th St., 720-465-9063; <a href="http:/...
0
votes
0
answers
40
views
preg_match last characters after hyphen [duplicate]
Can anybody help me please. I get an url and need to take the last part after -.
Example data
game-when-no-one-at-xhU8c0dL
coins-at-the-desk-1xhz83c
example-example-1391340
Result needed
xhU8c0dL
...
-1
votes
1
answer
40
views
preg_match pattern matches (php)
I have a string, such as
"<span class="m-product-data-3__price-value" itemprop="price" content="143.28">XYZZZ</span>"
or
"<span class="...
-1
votes
1
answer
33
views
I want to put the data from a text file and remove something certein from in between, and want to repeat the same
I have a text file and in that text file there is some data goes like
John || Sekram
JOHN || Doe
Lorem || Ipsum
now my problem is i dont know where to start but i want to put this data in to tow ...
3
votes
1
answer
79
views
Regular expression in PHP, with range of characters, but that excludes specific ones
I'm trying to create a regular expression with preg_match that can detect a string with the following requirements:
Must contain at least 10 characters.
There must be at least one of these: / (slash) ...
1
vote
4
answers
147
views
Replace text with preg_match_all using PHP
I have this string:
The product title is [title] and the price is [price] and this product link is [link]
and I have a variable called $get_product whch contain associated array.
Now, I want to ...
0
votes
1
answer
68
views
preg_match_all is not working or showing result
{"popUp":false,"token":"NS2938f08ubjk765vhjJBKJB78vhjeec1_m1_7"}
This is curl response in JSON, and i want to extract token from this JSON response.
i used ...
0
votes
3
answers
134
views
PHP: Splitting a string into an array around words wrapped in tildes & keeping those words
It's very late and I think I've been staring at this too long to figure out, but: I have been provided a bunch of raw text where anything within in tildes (~) is a title, and everything else is just ...
0
votes
0
answers
19
views
How do i validate a company email using php preg_match function [duplicate]
I am trying to use the preg_match function in php to validate a company email. I have done some general email validation using the same function before but in this case i want the pattern to suit ...
-2
votes
2
answers
137
views
PHP Regex Get Text Between and inside tags
I have this tag on an HTML code:
text html [button link="google.com" color="#fff" text="this text here"] rest of html
I wish i could have the parameters of this "...
0
votes
1
answer
81
views
PHP MySQL Negative Wildcard Character List
To secure a HTML GET method form submission so that users cannot use MySQL wildcards to get the whole table values, I was looking for a list of PHP-MySQL wildcard characters.
For example, this GET ...
1
vote
2
answers
214
views
PHP preg_match for getting a string out with variable length
I have the following string example: 034a412f500535454e5
Here I would get the 500 out.
The search-string has always 8 digits in front and 8 digits behind. The "500" can have a different ...
1
vote
1
answer
63
views
PHP: How to find a big word in a small one
I have user input like:
$name = 'Alexxxx'
Or
$name = 'Aaaalex'
And I have list of names like:
$names = 'Jack Harry Alex Oscar'
I need to know that user input contains name from a list, but user can ...
0
votes
1
answer
65
views
php PCRE functions very slow
I create a simple script for search words inside a txt file.
<?php
$search_term = "lorem";
$file = file('textfile.txt');
foreach($file as $line_number => $line){
$row = preg_match('...
0
votes
0
answers
247
views
composer update -v display an error : [ErrorException] preg_match() expects parameter 2 to be string, array given
I am hosting my laravel 8 project. When I execute the command composer update -v and also other commands with composer in my Ubuntu 18.04.5 LTS server, the errors below are displayed
[...
0
votes
1
answer
151
views
How to exclude vertical bar from escaping in preg_quote()
I have an array the elements of which are paths and contain forward slashes and exclamation marks.
And I need to inject such an array as regex pattern to preg_match()
$url = 'example.com/path/to/!...
-1
votes
1
answer
46
views
How do I get value from ocrTextBox (2552)?
I Have This
How to get value from ocrTextBox(2552)
????????????
$res='<script>
$("#submit_i2ocr").removeAttr("disabled");
$("#tools").show();
var aTag = $("a[...
0
votes
0
answers
52
views
Problem: Modifying existing php code to add telephone validation to form. Have the correct preg-match but not working. Any text entered is accepted
I was using some pre-existing open source code and wanted to add a telephone validation to a form. The original code did not have a telephone validation. I tried to mirror the email php validation ...
0
votes
1
answer
43
views
How to write regular expression to Validate phone number of format (0d)dddddddd in php using preg_match?
I have been trying but not sure where i am wrong
$validator = preg_match('/^\(\0\d{1})?\d{8})$/', $phone);
if($validator == true)
{
echo "Valid phonenumber";
}
else
{
echo "...
0
votes
1
answer
824
views
PHP- combining two params within match() expression to be set dynamically
I am trying to set two parameters within my PHP project. One is sortBy and second is orderBy..
I am trying to define the best logic for it using match() expression, available from PHP 8.0 version.
$...
0
votes
1
answer
53
views
Why would you call array_shift on the matches returned from preg_match?
I am trying to develop a framework using PHP while learning, and came across this logic for URL routing using regex:
public static function on($regex, $cb)
{
$params = $_SERVER['REQUEST_URI'];
...
0
votes
0
answers
29
views
Convert JavaScript regular expression to PHP [duplicate]
I have following JavaScript code with regular expression which is working as expected.
var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[\w~@#$%^&*+=`|<>'{}:;,!.?/\\"()\[\]-]{10,99}$/;
...
0
votes
1
answer
78
views
preg_match exact world - no partial by array
Hello everyone I made this php code
$variablename = "Marron";
$tallas = '#^/' . implode(array("XL", "L", "M", "S", "XS"), '|') . '/#';
if (...
0
votes
0
answers
33
views
what is the right expression to remove part of a string starts with EN/ in a string?
I want to delete lang-code(EN/DE/FR/IT/JA/ES) out of a string but i dont know the right expression can someone help me ?
the Lang-code string always starts with EN/ and the end is variable
i know i ...
0
votes
1
answer
37
views
php regex lookahead - exclude character
I’m trying to extract three parts with a regular expression.
It works for the controller and the id but not for the slug, I can not remove the last -
<?php
$url = "/cockpit/posts/my-...
2
votes
1
answer
57
views
Preg for checking how many time it occurs
Here I am having one preg
[-0-9a-zA-Z \/_:.,;=\'{0,2}"{0,2}\s]+$
With this I want to check lines whether they contains Alphabets, Numeric and some special character such as - _ , . ; ' " / =...
0
votes
1
answer
327
views
Finding a way to preg_match all special letters
Basically I was trying to preg_match all Letters and special letters for example: ä,â,ã… But I‘ve come across to a problem. Preg_Matching only letters was pretty easy since you only need the following ...
0
votes
0
answers
92
views
preg_match alphanumeric and hyphens only
I'm trying to see if a string contains only alphanumeric characters or hyphens
Right now I have this code to check for alphanumeric
if (ctype_alnum($string)) {
//do something
}
and have tried ...
0
votes
1
answer
119
views
How to preg_match greater/less than number in php?
I am trying to create an input field to input the amount. If the amount is less than 200 it will show the error message.
This is the code:
<?php
$paid_amount = sanitize_text_field( $_POST['...
1
vote
2
answers
371
views
Preg_match / split barcode
I am struggeling with reading a GS1-128 barcode, and trying to split it up into the segments it contains, so I can fill out a form automatically.
But I can't figure it out. Scanning my barcode gives ...