5,835 questions
0
votes
1
answer
70
views
Unable to create regular expression for preg_replace [duplicate]
There is a program php7.4
<?php
$text1 = "eggs";
$ll = 'e.g.';
$text2 = preg_replace(["/\b{$ll}\b/", ], ["<b>{$ll}</b>", ], $text1);
As a ...
0
votes
0
answers
48
views
PHP preg_replace problem, add space before and after a slash everytime slash is preceded by an alphabetic char [duplicate]
I have some problems with regular expressions. I'm using PHP preg_replace function to add a space ( ) after and before / everytime the / is preceded by an alphabetic char.
I have this one
$text = ...
1
vote
3
answers
65
views
Remove more than 1 blank line between paragraphs with only 1 blank line AND remove excess white spaces
I have a website where users are required to write a simple, short profile description. Some users are writing ugly profiles with a bunch of empty spaces, and excess new lines. It's a lot of work to ...
-7
votes
1
answer
119
views
Replace the querystring of an href declaration in an <a> tag
I want to replace the following hyperlinks dynamically
from
<a href="/xsearch2?q=some search/21">21</a>
to
<a href="/xsearch2?q=some search&page=21">21</a&...
-1
votes
1
answer
91
views
How to use PHP preg_replace on a formatted number based on search query while ignoring comma and decimal?
I want to highlight my search query on a formatted number.
For example:
$search_query = '1234'; // or $search_query = '7800';
$formatted_numeber = '12,345,678.00';
Currently my code is:
preg_replace('...
0
votes
1
answer
72
views
PHP - replace text and check for file?
I have this simple line of php
$text = preg_replace("/\\ii(.*?)\\<>/", "<img scr='img/$1'>", $text);
Where I change II30.jpgII to <img scr='img/30.jpg'>, and it ...
1
vote
0
answers
86
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
0
answers
32
views
Using preg_replace for bbcodes to convert texts
I'm in the process of upgrading my site's engine. The new version does not support bbcodes, and all my forum posts and articles are created using it.
I want to make a script to convert all text with ...
4
votes
3
answers
148
views
Converting this preg_replace to match a word with a plus
In PHP I need to highlight multiple given words in a string, for example wrapping found matches inside a <em> tag.
But if I have a word ending in + I cannot do it.
I understand the below problem ...
0
votes
0
answers
25
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 ...
0
votes
1
answer
117
views
Replace only the first occurence of two special characters, the rest are removed and no numbers [closed]
I need a php preg_replace to allow only the first occurence of ' and -, the rest will be removed and no numbers and other special characters. So Mike O' Hara's Du-Pont Check-In will become Mike O' ...
0
votes
0
answers
69
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) ...
0
votes
1
answer
74
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
65
views
Replace preg_replace with preg_replace_callback due to e modifier deprecation
Get a warning because the e modifier deprecation on preg_replace function.
Here is the code, I suggest that should be replaced by preg_replace_callback function (for php 7.4.16) :
`$text = ...
0
votes
2
answers
105
views
PHP perl regular expression - URL not preceded by equal sign and possible single or double quote
I'm trying to create a perl regular expression that matches a URL that is not preceded by an equal sign and one single or double quote (optional) ignoring whitespace. The code below gives an error: ...