5,831 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
3
answers
75
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
129
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
97
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
79
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
91
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
37
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
149
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
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 ...
user avatar
user3014233
0
votes
1
answer
123
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
84
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
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
69
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
106
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: ...
0
votes
2
answers
53
views
Remove tag with a specific attr from text PHP
I have a span tag that has role attr button. What I want to achieve is to remove the whole span while matching not the span itself but the role attribute
$str = 'This is a test buton. <span id=&...
-1
votes
1
answer
107
views
Replacing quotes with single quotes between two strings in php using preg_replace [duplicate]
I'm looking for a preg_replace that can replace " with ' when between font-family: and ;
I'm having an issue with my some dynamic html I'm using which requires me to replace the quotes with ...