413 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
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
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 = ...
-2
votes
1
answer
96
views
Ignoring word when its between a specific combination of words in regex (glossary link implantation)
I have edited my question and simplified it.
I created a function to highlight glossary in text that can be used to highlight conjugated words (in french). I works great but I want to ignore words ...
0
votes
2
answers
94
views
Convert html headlines to list elements in PHP
I am learning php language.
I want to show the table of contents for the article. Convert the headings (h2,h3,h4,...) into a list and create links.
This is my php code.
$Post = '
<h2>Title 01<...
0
votes
2
answers
82
views
Enabling preg_replace_callback() replacement function if it's loaded from string
I have input strings like
Wires: 8 Pairs: 4
The both numbers may be different for different strings
So, only dividing and only numbers can be different
I need to get the output result like
Wires: 2 ...
1
vote
0
answers
36
views
How can I restrict preg_replace_callback so that it replaces a limited number of expression matches?
An example of what I need:
$input = "bar bar bar bar bar";
$result = preg_replace_callback('bar', 'foo', $input); // And there must be some way to limit preg_replace_callback so that it ...
0
votes
1
answer
153
views
Add year function boolean and replace 3-letter month with its month number in an array of strings
Background information:
The log file is copied and read out at regular intervals.
Log file lines do not have a year specification.
Months are continuous.
Before January is always the previous year.
...
0
votes
3
answers
277
views
Replace 3-letter month with its month number in an array of strings
Search in the array for the first occurrence of a string until space, then convert it to month.
$arr = [
"May Hello",
"Jun Hello12",
"Jul 3"
];
$str = $arr[0];
$...
0
votes
2
answers
278
views
replace string in template file
I do have that code:
ob_start();
include($this->testTpl);
$html = ob_get_clean();
$pattern = '/{{{\s*(.+?)\s*}}}(\r?\n)?/s';
echo preg_replace_callback($pattern, function($matches) {
return &...
3
votes
2
answers
133
views
PHP preg_replace_callback creates false entries in matches for named groups
I have a couple of "shortcode" blocks in a text, which I want to replace with some HTML entities on the fly using preg_replace_callback.
The syntax of a shortcode is simple:
[block:type-of-...
1
vote
1
answer
76
views
Removing line breaks between 2 different character sequences
I'm editing a csv file which contains hidden line breaks. When I apply the following php script, the line breaks are successfully removed from the entire file.
$csvFileNew = str_replace(array("\r&...
-4
votes
1
answer
706
views
How to remove all href link but exclude some specific href links
<?php $string = 'this is just testing <a href="https://twitter.com/blalala/status/1523867438743711744">twitter</a> visit google <a href="https://www.google.com/search?...
2
votes
0
answers
85
views
Regex Template Parser ignore new lines
I am trying to build a "simple" RegEx parser, to generate some templates in my project.
I have made this bit of regex to match and parse loops - which seems to be correct and finding ...
-1
votes
2
answers
2k
views
How to replace below preg_replace with preg_replace_callback?
I am having difficulty converting below preg_replace() function call
preg_replace("/\{(.*?)\}/e", '$1円', $data)
to using preg_replace_callback() (because of the removed e modifier in PHP 7....
0
votes
1
answer
212
views
How to create a pattern to use in preg_replace_callback() function in PHP
I am upgrading my PHP Application from PHP 5 to PHP 7 for which I am required to replace all the references of preg_replace() function to preg_replace_callback() function.
I am having a hard time ...