Questions tagged [preg-replace]

preg_replace() is a PHP function that performs string replacement using regular expressions.

preg_replace() is a function member of Perl Compatible Regular Expressions implementation of .

Check out PCRE in the official PHP documentation

5858 questions
1
vote
4 answers

How to add a character to the front of all numbers seperated by whitespace in a string using php

I have a string filled with numbers and i'm trying to add a character to the front of every number series: $dna = "273385 14093 1522520 1759 277697 283096 1133193 191835 246752 204984 973590" but I want to end up with: $dna = "m#273385 m#14093…
Fight Fire With Fire
  • 1,626
  • 3
  • 19
  • 28
1
vote
1 answer

preg_replace for "phpbb" quote and color tag from string

I have a string like below and I want to parse the quote tag tag to
"Content
and want to replace the color tag with an empty string. Input: [quote="De real one ROOFVISSER":g3o3w038][color=green:g3o3w038]Thnxxx voor…
Raj Jagani
  • 738
  • 1
  • 6
  • 21
1
vote
1 answer

JHtml-"email.cloak" doesn't recognize email address when using preg_replace() in joomla

I try to substitute an email-address within a text in a module with php using JHtml::_("email.cloak", "some@email.com"), in order to cloak it on a joomla 3.9.2 webpage. using following sample code:
1
vote
2 answers

PHP Using preg_replace_callback shortcodes function returns wrong elements order

I'm defining a function which can handle shortcodes for users wisiwyg made posts. Using a function based on preg_replace_callback works great, but the returned replaced values prints before the initial string This is the handler function function…
quakeglen
  • 165
  • 3
  • 7
1
vote
2 answers

php preg_replace help iframe src

I have created a function which will set height, width and wmode=transparent for youtube embed codes. Now youtube is returning iframe code. So, I need to append "?wmode=transparent" at the end of youtube src. For eg. Original code :
aayushi
  • 161
  • 6
  • 17
1
vote
2 answers

linux c/c++ preg_replace type of function?

I'm trying to figure out an preg_replace() (php) style function that I can use in c++ (linux). Can someone help me translate this? $str = preg_replace(array('/\s+/','/[^A-Za-z0-9\-]/'),array('-',''),$str);
Joe
  • 3,043
  • 9
  • 43
  • 56
1
vote
0 answers

Preg_replace not working properly for $(dollar) symbol in php

In Php Preg_replace When we have using $ then it remove the int near by example $pattern = '/\*\|Coupon\|\*/i'; $coupon = '$15t'; $string = 'test coupon *|Coupon|*'; echo preg_replace($pattern, $coupon, $string); Then the output is 't' but expected…
Raghul R
  • 21
  • 3
1
vote
1 answer

Replace html content without replacing the tags or attributes - PHP

How can i replace content inside or outside HTML dom without replacing the HTML tags or attributes? e.g $txt='good
good
' $search='good'; $pattern = '#(?!<.*?)(\b'.$search.'\b)(?![^<>]*?>)#si'; $replacement =…
General Omosco
  • 606
  • 1
  • 10
  • 20
1
vote
2 answers

php preg_replace comment blocks

the patern is like so /* comment [comment goes here] */ /* comment please do not delete the lines below */ [I am a special line so I should not be changed ] /* comment please do not delete the line above */ I would like to remove the comment…
Val
  • 17,336
  • 23
  • 95
  • 144
1
vote
1 answer

PHP Regex Replace Subject while keeping case

I am using preg_replace to swap U.S. words with their British variants in HTML. function makeUK(&$str){ $delta = [ 'authorize' => 'authorise', 'center' => 'centre', 'theater' => 'theatre', 'capitalize' =>…
yevg
  • 1,846
  • 9
  • 34
  • 70
1
vote
1 answer

How to keep digit and special character in preg_replace

I want to replace {goal} braces with a price such as $45. for example $pattern = /\{goal\}/ $replacement = $45.00 $subject = Final price is {goal} so the function looks like preg_replace('/\\{goal\\}/', '$45.00', 'Free shipping for all orders…
chirag dodia
  • 515
  • 1
  • 7
  • 17
1
vote
3 answers

Regular Expression for urls for images and links

EDIT: I'm not parsing html like the 5 billion other questions that have been posted. This is raw unformatted text that I want to convert into some HTML. I'm working on a post processing. I need to convert Urls with image endings (jpe?g|png|gif) into…
LeviXC
  • 1,075
  • 2
  • 15
  • 32
1
vote
1 answer

Formatting decimal output when multiplying all numerical values in a string?

I have this case where I have to multiply the numbers of a string but some of the values are in EUR and some are percentage. I made it this far as code goes: $string = "description: test1: 10 €, test2: 7.50 €, test3: 25%, test4: 30%"; …
lion
  • 97
  • 2
  • 13
1
vote
2 answers

escape $0, $1, .. with preg_replace

I have something similar to this: I want the final value of $text to be 'test $0 ipsum'. Problem is $0 is interpreted as a…
1
vote
3 answers

how to remove the comment line starts with // and not the url like http:// using preg_replace

I need to remove the comment lines from my code. preg_replace('!//(.*)!', '', $test); It works fine. But it removes the website url also and left the url like http: So to avoid this I put the same like preg_replace('![^:]//(.*)!', '', $test); It's…
Coder
  • 21
  • 2
1 2 3
99
100