【发布时间】:2019-11-02 09:16:44
【问题描述】:
我有一个要向其发送链接列表的脚本。如何删除 url tail 并仅保留域?例如:只留下 google.com,而不是 google.com/adwords。
<form method='post'>
<textarea name="url1" cols="40" rows="5"></textarea><br>
<input name="Submit" type='submit' value='Send'>
</form>
<?php
$array = explode("\r\n", $_POST['url1']);
$word_count = (array_count_values($array));
arsort($word_count);
foreach ($word_count as $key=>$val) {
echo '<a href="' . $key . '">' . $key . '</a> - ' . $val . '<br/>';
}
?>
我尝试了类似的方法:
$string = array('https://google.com/ytrewq', 'https://google.com/qwerty');
$pattern = '/[^/]+$/';
$replacement = "replacement";
print_r (preg_replace($pattern, $replacement, $string));
print_r (preg_grep($pattern, $string));
print_r (preg_filter($pattern, $replacement, $string));
print_r (preg_match($pattern,$string,$found));
但它不起作用。
【问题讨论】: