Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
87 views

How can I make a dynamic replacement with a std object? I can't get how to use $1 in this case :( See below. $lang->custom_name = "Me"; $lang->custom_email = "Me@me"; $html =...
rosia's user avatar
  • 229
1 vote
1 answer
235 views

Sorry for this, I am a very old developer. After have been stopped developing 6 year ago due to a serious cerebral infarction my head is not so fresh anymore, I forgot many thing and also, as you can ...
Franco's user avatar
  • 2,329
-2 votes
1 answer
199 views

I am trying to replace hyphens in text to non-breaking hyphens, but I need to exlude all URLs, emails and tags. Here is some text I am trying to edit: Some text with a link but also plain URL like ...
hyst's user avatar
  • 3
0 votes
1 answer
57 views

I'm trying to do a preg_replace to change the title of my pages since everything is below the header and title tags. I used this example https://stackoverflow.com/a/32508962 and edited it slightly for ...
Jakob Glantz's user avatar
2 votes
1 answer
30 views

Here's i have an issue : sentence : "12223233 sekamar berempat" $kamar = $_POST['kamarpilihan']; $kamarhuruf = preg_replace("/[^a-z]+""/", "", $kamar); result: sekamarberempat ...
rayhan aulian's user avatar
2 votes
1 answer
103 views

How can I insert the character before and after in a character but ignore whitespace between two character or more. I try this regex but it's return incorrectly $str = " echo '<pre>';...
Jerson's user avatar
  • 1,775
-1 votes
3 answers
388 views

<?php $str = htmlspecialchars('<nav><a>something</a></nav>'); $pattern = htmlspecialchars('/<nav><a>something</a></nav>/i'); echo htmlspecialchars(...
Adwaith's user avatar
  • 11
0 votes
0 answers
262 views

I have an example: some text lorem ipsum ... {gallery}../2021/some_string_2021/some_other_string{/gallery} ... other lorem ipsum And I need to get out only the ../2021/some_string_2021/...
Kiki FIstrek Novi's user avatar
0 votes
1 answer
894 views

I have &nbsp; tags as spaces in autocreated posts in Wordpress and trying to replace them before posting/saving. Text sample below: This&nbsp;is&nbsp;an&nbsp;Example&nbsp;of&...
Carlos Qonthair's user avatar
1 vote
4 answers
266 views

I'm struggling with some regular expressions. What I want to do is find money amounts in a string, remove the €,$, or £ but keep the number, and then look to see if there is a 'b' or an 'm' - in which ...
Matthew Brown aka Lord Matt's user avatar
-1 votes
1 answer
94 views

When registrants sign up, they often add a leading 0. I would like this to be removed after registration. I have tried the below, but it's not working (cq it's not updating the proposed outcome). ...
Demian's user avatar
  • 546
0 votes
1 answer
449 views

I am currently using this snippet to change the text from [[foo]]to a full HTML a link. $var = preg_replace('/\[\[((.*?)(\|(.*?))?)\]\]/', '<a href="https://foobar.com/$1">$1</a>'...
penguinstyles's user avatar
-1 votes
1 answer
471 views

I'm trying to strip hidden control chars (especially \x{89} and \x{88}) with preg_replace() from a string. It is "ˆText" (it starts with an "\x{88}" char), mb_detect_encoding says ...
alessandro's user avatar
0 votes
3 answers
511 views

So I am trying to make a morse code encoder/decoder; I got the encoder done, but the decoder is giving me some problems. So, if I use the function test and input "ab" it will return "ab&...
Crimin4L's user avatar
  • 615
1 vote
1 answer
947 views

I recently wrote a code which uses file_get_contents along with some USER_AGENT headers and other headers to get a source of a m3u8 file , when echoed it looks like following #EXTM3U #EXT-X-STREAM-INF:...
Piyush's user avatar
  • 51
1 vote
2 answers
123 views

$str = "Hello 1234567 Stack 56789 Overflow 12345"; $str = preg_replace('/([0-9] )/', ',', $str); I want this "Hello 1234567, Stack 56789, Overflow 12345,..."
jav feli's user avatar
2 votes
1 answer
89 views

I'm trying to replace words in PHP using preg_replace. When executing the code, it will replace "fuel cap for car" with "cap", as opposed to "auto parts". $string = "...
MOrange89's user avatar
2 votes
2 answers
331 views

How can I match what's between a . and a { and merge them onto a single line without touching the spacing between them. This regex (\.|@)[^}]*\{ inculdes the ending { no matter what I try, and I need ...
Norman's user avatar
  • 6,395
2 votes
2 answers
1k views

I'm trying to remove line breaks and tabs from content that's inside brackets from data like this: settings:a [ a:[ a:a b:b ] b:[ a:a b:b ] ] settings:...
jmenezes's user avatar
  • 1,936
-1 votes
1 answer
50 views

<?php $teststring = <<<STR aqbrakadabra doom <style> <script> sdgdfsf <?php <? dfsaasdf <? phpinfo(); ?> STR; print preg_replace("/\<\?(php){0,1}|(sys)[a-...
Sylwester Marć's user avatar
1 vote
1 answer
89 views

Variable string contains lines as important 1 some words ...... IMPORTANT 34 some words ...... important 99 some words ...... The goal is to remove the lines containing the word important ignoring ...
www.friend0.in's user avatar
0 votes
1 answer
726 views

I use this code to make urls clickable as anchor links in forum posts. function makelink($str) { $str = preg_replace_callback('/((((http)(s)?:\/\/)|www\.)[-0-9æøåa-zA-Z?-??-?\(\)%_+\.~#?&;:@\/...
mowgli's user avatar
  • 2,859
0 votes
1 answer
1k views

$regex = array( "`^([\t\s]+)`ism"=>'', "`^\/\*(.+?)\*\/`ism"=>"", "`([\n\A;]+)\/\*(.+?)\*\/`ism"=>"...
Meir Levi's user avatar
0 votes
1 answer
111 views

I'm using Simple HTML Dom Parser to correct some links in my output to good effect but have found some strange behaviour when calling content via Ajax. I'm using the parser on a WordPress site so feed ...
Kevin Nugent's user avatar
0 votes
1 answer
39 views

i can't figure out this thing i think it possible with only one pattern, please help me improve. I have this string 2 / 3 items and i wont receive only 2 / 3 Items can also be write in cirillic so 2 / ...
Artur Mamedov's user avatar
3 votes
3 answers
244 views

< EDIT > I Wanted to give a big thank you to all of you who have provided an answer, You have all given me great options. I will play with each and see which one suits my exact needs prior to ...
DrCustUmz's user avatar
1 vote
2 answers
49 views

I am trying to transform this: §f§lWORDHERE in this: <span style="color: white;><b>WORDHERE</b></span> I thought that with this I would achieve it, but apparently it is ...
Axel Benitez's user avatar
0 votes
1 answer
36 views

So, I'm doing some manipulation on lat/long pairs, and I need to turn this: 39.1889375383777,-94.48019109594397 into: 39.1889375383777 -94.48019109594397 I can't use str_replace, unless I want to ...
Andy Wallace's user avatar
2 votes
2 answers
95 views

There is a string in format: else if($rule=='somerule1') echo '{"s":1,"n":"name surname"}'; else if($rule=='somerule2') echo '{"s":1,"n":"another ...
Okumaima's user avatar
0 votes
1 answer
401 views

I have the following code: $f = 'IMG_1474.PNG'; preg_replace('/(.*)([.][^.]+$)/', '$1' . time() . '$2', $f) which should split the IMG_1474 and .PNG and add the epoch in between. The first capture ...
user3783243's user avatar
  • 5,212
0 votes
1 answer
390 views

I need to filter out all, but alphanumeric, Latin-Chars AND emojis $str="Hello José' [](){}✅🎧🎬., welcome"; wanted result: Hello José ✅🎧🎬 welcome echo preg_replace("/[^\p{Latin} \wp-...
david's user avatar
  • 100
0 votes
0 answers
23 views

I have this code and works correctly but I'm wondering if it can be optimized to not repeat the formats in capitalize & lowercase (?:mp4|MP4|webm|WEBM|mov|MOV|ogg|OGG)) $post[message] = ...
Akirabyte's user avatar
-1 votes
1 answer
44 views

I belive minimal is better, so I'm wondering how could I reduce/optimize these 5 lines in 1 line? #JPG $post[message] = preg_replace('/<a href="(.+?)\.jpg" target="_blank">(.+...
Akirabyte's user avatar
1 vote
1 answer
100 views

I have a code like this : <?php add_filter('the_content', 'my_url_replacer'); function my_url_replacer($content) { $params = $_SERVER['QUERY_STRING']; if($params) { return ...
Hendra Setiawan's user avatar
0 votes
1 answer
165 views

I would like to remove some hashtag including japanese and I encounter a problem that some words are not able to be removed. $text = "#食への好きな人と繋かりたい #食への好きな人と繋がりたい #食べるの好きな人と繋がりたい"; echo ...
fmchan's user avatar
  • 761
0 votes
1 answer
91 views

Let say I have a string $content = "hello . wow . cool . yes!"; It's easy to just replace the dot to another string: echo preg_replace("/\./", "<img>", $content); ...
fmchan's user avatar
  • 761
0 votes
1 answer
290 views

Assume I have the below text in the database. $str = 'Test text http://hello-world.com Test text http://google.com/file.jpg?google=1 Test text https://hell.o.wor.ld/test?qwe=qwe Test text text text ...
Jigar's user avatar
  • 3,283
1 vote
1 answer
927 views

I have a string in PHP, i'm able to remove multiple continuous break lines and multiple spaces, but what i'm still not able is to remove multiple break lines if i have an space in the middle. For ...
Miguel's user avatar
  • 568
-1 votes
1 answer
354 views

How can I convert all multiple white space inside any given HTML element to a single space using regex and preg_replace in php? Eg: <div class="myClass" jsaction="UjQMac:.CLIENT&...
Norman's user avatar
  • 6,395
1 vote
2 answers
523 views

I would like to replace the word "custom" with <span class="persProd">custom</span>. This is my code but not work: $output = '<a href="www.mysite.com/custom-...
Jackom's user avatar
  • 436
1 vote
3 answers
64 views

With PHP, I'm trying to use preg_replace to convert a group of words separated with an underline into a "reference" composed of the first letter of each word except for the last one in the ...
MaxAuray's user avatar
  • 513
0 votes
0 answers
100 views

There are 2 codes, PHP and JS. The work of the codes is exactly the same. The duty of the codes is to count words. However, there is 1 difference between PHP and JS results. The reason for this ...
Morgan Codes's user avatar
1 vote
2 answers
68 views

I use this code to select 2 words around either side of a word. ((\w+\W+){0,2}WORDHERE(\W+\w+){0,2}) But it treats apostrophe-separated words as "two words". For example, with the input ...
Joe's user avatar
  • 143
-3 votes
2 answers
39 views

I am stuck with this. I tried json_decode but it gives me an error. How can I remove the "[]" and the ' " " ' characters of my string? I have a string with this values ["Red ...
Jc John's user avatar
  • 1,859
1 vote
1 answer
549 views

I have a tricky string of HTML code that includes several pre tags that inside them include code (say, python), and that are also decorated by HTML tags that should be removed. For example: Some text. ...
Tal Galili's user avatar
  • 25.5k
0 votes
1 answer
1k views

I want to remove all comment inside a JSON object except the one that are inside a string. For example: { //Remove this comment "Command": "storeSystemConfig", "...
Micket's user avatar
  • 17
0 votes
1 answer
92 views

I had the following PHP Regex code, to replace all emails with a "[removed email]" replacement string; and it worked nicely: $pattern = "/[^@\s]*@[^@\s]*\.[^@\s]*/"; $replacement =...
jjj's user avatar
  • 2,702
0 votes
1 answer
37 views

I am trying to print a preg_replace result outside the loop it is made. This is my code $search = "Lola and Chris"; $query_gdpr_names = "select name FROM gdpr_names"; $...
lStoilov's user avatar
  • 1,351
1 vote
3 answers
142 views

I have a very long list of names and I am using preg_replace to match if a name from the list is anywhere in the string. If I test it with few names in the regex it works fine, but having in mind that ...
lStoilov's user avatar
  • 1,351
2 votes
2 answers
663 views

I have a string from which I want to replace only the odd positions by a random digit. For Example, the string is '123456'. Now the output I want is '528496'; Note that the digits 1,3,5 in odd ...
user avatar

1
3 4
5
6 7
117