A
A
Alexey Semenyuk2018-03-14 22:04:52
PHP
Alexey Semenyuk, 2018-03-14 22:04:52

How to write a regular expression in php?

$text = '"i":"https://mylink.com/2634/2634441_200x200.jpg","l';
  $pattern = "|\"i\":\"https://[^\"]+\/|is"; 
  $text = preg_replace($pattern, "\"i\":\"http://newlink.com/", $text); 
  echo $text;

here it is necessary that only mylink.com changes in the text and at the same time mylink.com is dynamic, something similar was found, but it cuts off a little total
"i":"http://newlink.com/2634441_200x200.jpg","l
instead of
"i":"http://newlink.com/2634/2634441_200x200.jpg","l

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2018-03-14
@wonchoe

$pattern = "|\"i\":\"https?://[^/]+/|is";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question