0
如何使用preg_replace
替換我的文本中的null
單詞並以用戶名結尾的網址?preg_replace null與特定數據
例如:
更換null
在此
(1, 3, 'sam', 'sam-website', 'yes', 'null'), (2, 3, 'alex', 'alex-website', 'yes', 'null'), (3, 3, 'kabor', 'kabor-website', 'yes', 'null'),
得到這個
(1, 3, 'sam', 'sam-website', 'yes', 'http://mywebsite.com/pics.php?id=sam'), (2, 3, 'alex', 'alex-website', 'yes', 'http://mywebsite.com/pics.php?id=alex'), (3, 3, 'kabor', 'kabor-website', 'yes', 'http://mywebsite.com/pics.php?id=kabor'),
試過,但它不工作
$name = preg_match('/3, \'(.*?)\',/im', $string, $matches);
$url = preg_replace_callback('/null(?=)/', function ($name){
return ($matches[1]);
}, $string);
哪種格式*說*數據是?您應該在**到* null *格式之前操作數據**。 –
其JSON格式 –
請向我們展示獲取此* null *格式數據的代碼。就像我說的那樣,如果您事先操作和格式化數據,對您來說會更容易。 –