0

I want to change the id partner=852501 to partner=985412 in my code, but stuck in this step. Example:

http://a-ads.com/?partner=852501

My attempt:

([1-z0-9\/]+)\/\/(a-ads\.com\/?)

How to do the right thing?

Srdjan M.
  • 3,310
  • 3
  • 13
  • 34
  • Have you chacked [Using php replace regex with regex](https://stackoverflow.com/questions/22040272/using-php-replace-regex-with-regex)? – Munim Munna Mar 30 '18 at 18:52

2 Answers2

2

Regex: partner=\K[^&]+

Details:

  • \K resets the starting point of the reported match
  • [^&]+ Match a single character not present in the list & one and unlimited times

PHP code:

preg_replace('/partner=\K[^&]+/', '985412', $url);
Srdjan M.
  • 3,310
  • 3
  • 13
  • 34
0

preg_replace you can replace the value

 $string = 'http://a-ads.com/?partner=852501';
 $your = 985412;

 echo preg_replace('/(\d+)/', $your, $string);

UPD: The value can be obtained with the help of preg_match

preg_match('/partner=(\d+)/', $string, $match);

echo $match[1];
Octavian
  • 155
  • 8