skip to Main Content

Weird PHP preg_replace result

$pedit =<<<head <div class="item"><div var="i_name_10">white gold</div> <div var="i_price_10">$5.99</div></div> head; $pedit = preg_replace("/(<.*var="i_name_10".*>)(.*)(</.*?>s*)/","$1"."aaa"."$3",str_replace("> <","><",$pedit)); RESULT: white gold $5.99 aaa Expected result is aaa $5.99 When I put a newline after newline after the "white gold" div or put a U after…

VIEW QUESTION

Problems using preg_replace – PHP

Regx is not my thing. I have a large file where I want to replace the following example: <g:id><![CDATA[131614-3XL]]></g:id> should be replace with: <g:id><![CDATA[131614-3XL]]></g:id><g:id2><![CDATA[131614]]></g:id2> Please note that "-3XL" is deleted in id2 and please note that -3XL could be many…

VIEW QUESTION

How to exclude image extension from string place in PHP

I want to replace all the string values from example.com to sample.com excluding the image extension .png, .jpeg, .jpg etc. $body = ' www.example.com, example.com, example.com/hello.html, example.com/logo.png, example.com/yourbaby.php , example.com/newimage.jpg, www.example.com/newimage.jpg'; //values $oldomain = ['example.com','www.']; $newdomain= ['sample.com', '']; $excludeextension =…

VIEW QUESTION

Replace all domain including subdomain name using PHP with Regex

I am using preg_replace or str_replace in PHP to replace all the domain name including www $string = ' https://example.com, https://www.example.com, https://subdomain.example.com '; $olddomain= "example.com"; $newdomain = "stackoverflow.com"; $output = str_replace($olddomain, $newdomain, $string); $output = preg_replace('#(www[.])?[.]' . $olddomain. '#', $newdomain,…

VIEW QUESTION
Back To Top
Search