使用PHP preg_match更改字符串的最大宽度和最大高度


Using PHP preg_match to change the max-width and max-height of string

我有一个URL字符串,如下所示:

http://localhost/showimage.php?image=sunshine.jpg&max_width=158&max_height=158

对于preg_match,我要做的是将max_widthmax_height的值替换为下面的值:

http://localhost/showimage.php?image=sunshine.jpg&max_width=1000&max_height=1000

如何使用preg_match执行此操作?

请:

<?php
    $url = 'http://localhost/showimage.php?image=sunshine.jpg&max_width=158&max_height=158';
    $changedUrl = preg_replace('/(max_width)='d+|(max_height)='d+/', '$1$2=1000', $url, 2);
    var_dump($changedUrl);

此模式将"max_width"answers"max_height"值更改为1000。

尝试

preg_replace(
    '/(max_width|max_height)'='d+/i',
    ''1=1000',
    $string
)