Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
1 answer
41 views

Detecting OR operator sequences and wrapping their content in a parenthesis when building a query with PHP

I made the following PHP code to build a query based on user input, where they can choose the condition and the operator and the resulting query would be printed on their screen every time they added ...
Victor Canela's user avatar
0 votes
0 answers
20 views

Add Rewrite Rule Not Returning As Expected

I have the following code snippet in WordPress functions.php file: add_action('init', function() { add_rewrite_rule('^explore-destinations\/?(.*)','index.php?tt_destination=$matches[1]', 'bottom');...
Eric Levy's user avatar
-2 votes
0 answers
32 views

Regex Split a String into array [closed]

I have shown three types of string. I want to extract it into an array like $string = "Deluxe Single Room, 1 Bedroom,1 Large Twin Bed,NonSmoking"; $string1 = "Premier Double or Twin ...
B L Praveen's user avatar
  • 1,966
-1 votes
0 answers
19 views

Extract first paragraph tag from the string [duplicate]

I have array of string with Headlines or without Headlines $str = [ "Hotel Rest Inn is a traveler's delight. It has 18 rooms in the heart of Bangalore" "<p>HeadLine : Near Race ...
B L Praveen's user avatar
  • 1,966
1 vote
0 answers
44 views

How to extract arguments from a function and group them by type, int, string or array [closed]

Is there a way to extract function argument and group them by type: int, string or array from a substring with regex in PHP? I need to find all the arguments of type string and prefix them with the ...
Ludwig's user avatar
  • 21
1 vote
0 answers
35 views

Why doesn't regular expression /£?.*£?/ match string '£45.56–34.90' in PHP 8.2? [duplicate]

I'm using PHP 8.2.11 on Mac Sonoma 14.5. My code is: $cost = '£45.56–34.90'; $matches = array(); $found = preg_match( '/£?.*£?/', $cost, $matches ); I'd expect preg_match() to return 1, ...
pandammonium's user avatar
2 votes
0 answers
43 views

PHP PCRE2 conditional substitution

I'm trying to replace a string in a conditional way using preg_replace in PHP. The idea is pretty simple and it's working in regex101, but when i try it in PHP it doesn't. Search pattern: ^([0-9]{3})-...
j.c's user avatar
  • 2,863
0 votes
2 answers
92 views

Finding all types of end-of-line delimiters in a file [duplicate]

I have the following function to get all of the different types of end-of-line delimiters in a file. There may be one or more, so I want to return an array of all types. function ddtt_get_file_eol( $...
Aristocles's user avatar
0 votes
3 answers
103 views

Find Assignation in Condition using a Regex

I need a regex with which I could find if there is any assignation inside conditions. It needs to be as flexible as possible, because I will run this on many .php files to find such mistakes : <?...
Kolobo's user avatar
  • 39
1 vote
1 answer
47 views

Adjusting Regular Expression to Extract PHP Variables with Parentheses

I have a JavaScript function designed to extract PHP variables from a given string of PHP code. It works well for most cases, but I'm encountering an issue when the variables are enclosed within ...
sam's user avatar
  • 77
0 votes
0 answers
33 views

Replace non-breaking space between words [duplicate]

I'm trying with PHP to get rid of annoying non-breaking spaces between words that CKEditor + Chrome keep adding. Like Some text here&nbsp;and more text here But it's been a while and regex is ...
NaughtySquid's user avatar
  • 2,035
0 votes
0 answers
45 views

Do I need preg_replace_callback() to replace all matches in a text? [duplicate]

As part of a migration, I wrote a function to transform links, prepending a path ("/my/files") to existing paths from the source site. Here is my function: function example_file_urls($text) ...
arnoldbird's user avatar
1 vote
2 answers
98 views

Reverse the order of parenthetically grouped text and reverse the order of parenthetical groups

I have a strings with pattern, something like this: (X,1,1,3),(X,1,1,3),(X,@2,@2,@2,@2,@2,(Y,1)) And I need to extract from this One big array, reverse order, and generate new string: (X,(Y,1),@2,@2,@...
JozefVasko's user avatar
0 votes
1 answer
47 views

Regex to contain english, greek letters, numbers, spaces and commas

I have no idea how to syntax a regex in php. I want to check/validate that certain fields of a form contain only letters (greek or latin), numbers, commas and or numbers. So far I have this preg_match(...
Tolaso's user avatar
  • 185
0 votes
0 answers
35 views

Convert Creole List Formatting to HTML with PHP / RegEx

I have a small problem that I, my colleagues and ChatGPT are not really getting anywhere with. I have to change a creole formatting with PHP (Laravel Framework) to HTML. I wanted to do this with RegEx ...
ollo182's user avatar
  • 79

15 30 50 per page
1
2 3 4 5
2041