我有一个URL字符串,如下所示:
http://localhost/showimage.php?image=sunshine.jpg&max_width=158&max_height=158
对于preg_match
,我要做的是将max_width
和max_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
)