[Solved] How to strip parts of the given url using preg_replace (php) [closed]

For this specific case, you don’t need a regular expression, you can just parse the url $url=”http://dev.time.com/wp-content/uploads/2014/08/sheep-shrek-300×199.jpg?w=360″; $parts = parse_url($url); echo $parts[‘host’] . $parts[‘path’]; Missed that you want to strip the size … $data = preg_replace(‘/(-\d+x\d+)\.jpg/’, ‘.jpg’, $data); 1 solved How to strip parts of the given url using preg_replace (php) [closed]

[Solved] change URL in from anchor tag using preg_replace [closed]

There you go $patterns=”/pubmed\/2562222/”; $replacements=”http://www.ncbi.nlm.nih.gov/pubmed/2562222″; $string = ‘<a href=”https://stackoverflow.com/questions/16963490/pubmed/2562222″></a>’; print( preg_replace($patterns, $replacements, $string)); This will output <a href=”http://www.ncbi.nlm.nih.gov/pubmed/2562222″></a> Live Demo 3 solved change URL in from anchor tag using preg_replace [closed]

[Solved] remove all text before and after ‘[img id=”123″ align=”left”]’this and get this imageid and also remove the rest part of this stringi

You need to assign the result of preg_replace to a variable: $result = preg_replace($patterns, $replacements, $Story_Textarea); echo $result; // prints 55 with your sample text. solved remove all text before and after ‘[img id=”123″ align=”left”]’this and get this imageid and also remove the rest part of this stringi

[Solved] How to remove query string from “href” attribute of anchor using php?

Use /\?[^\”]+/ like bellow: <?php $string = ‘<a href=”https://stackoverflow.com/title/tt3110958/?ref_=nm_flmg_act_2″ style=”color:#666″ >’; $result = preg_replace(“/\?[^\”]+/”, “”, $string); echo $result; ?> Output : <a href=”https://stackoverflow.com/title/tt3110958/” style=”color:#666″ > 0 solved How to remove query string from “href” attribute of anchor using php?

[Solved] php regex preg_replace html tags

It would better to use a library like DOMDocument to parse the HTML. But if you really have to do it with a regexp…. Don’t use | in the regexp, that matches either class or id, but not both. preg_replace(‘~<div\b.*?\bclass\s*=\s*”(.*?)”.*?\bid\s*=\s*”(.*?)”.*>~i’,'<div class=”$1″ id=”$2″>’, $content); Note that this will only work if the class is to the … Read more