尝试编辑数组中的网址。
[0] => https://www.proud-web.jp/mansion/b115110/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244
[1] => https://www.proud-web.jp/mansion/p-ebisuminami88/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205
您看到的网址是这样的。尝试删除第一个网址并包含第二个网址。
预期结果如下:
https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244
https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205
我尝试过的东西就在下面。这样,我只能删除第二个。但是,如何解决此代码以删除字符串中的第一个url而不是第二个。
$result = [];
foreach($setLinks as $key) {
array_push($result, current(explode("/h", $key)));
}
答案 0 :(得分:1)
您可以使用foreach
后跟explode
来分割字符串w.r.t /https
。下面是代码:
$array = ['https://www.proud-web.jp/mansion/b115110/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244','https://www.proud-web.jp/mansion/p-ebisuminami88/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205'];
$result = [];
foreach($array as $arr){
$getUrl = explode('/https', $arr);
array_push($result, 'https' . $getUrl[1]);
}
print_r($result);
答案 1 :(得分:1)
这就是我要做的:
BEGIN
DBMS_AQADM.START_QUEUE('MY_USER.MY_QUEUE');
END;
输出
$urls = [
'https://www.proud-web.jp/mansion/b115110/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244',
'https://www.proud-web.jp/mansion/p-ebisuminami88/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205'
];
foreach($urls as &$url){
$url = 'http'.preg_split('/^.+?\/http/', $url, 2, PREG_SPLIT_NO_EMPTY)[0];
}
print_r($urls);
我将其设置为可以同时处理Array
(
[0] => https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244
[1] => https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205
)
和HTTP
答案 2 :(得分:1)
您可以使用preg_replace
删除开头的文本:
foreach ($setLinks as &$value) {
$value = preg_replace('#^.+(https?://.*)$#', '$1', $value);
}
print_r($setLinks);
输出:
Array (
[0] => https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244
[1] => https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205
)
答案 3 :(得分:1)
我将任务分为3个子任务。
://
作为分隔符分割字符串protocol . "://" . url
例如:
<?php
$array =
[
'https://www.proud-web.jp/mansion/b115110/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244',
'https://www.proud-web.jp/mansion/p-ebisuminami88/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205',
'http://www.example.com/home/http://something',
'http://www.example.com/https/ftp://something',
'https://nothing.to.capture'
];
$result = array();
/*
* matches a slash -> \/
* followed by letters -> ([a-z]*)
* followed by :// -> :\/\/
* and capture the letters -> (the parenthesis)
* it can match, in example : something/mycustomprotocol://somethingelse
*/
$pattern = "/\/([a-z]*):\/\//i";
foreach($array as $item) {
preg_match_all($pattern, $item, $matches);
if (count($matches) > 0)
{
$urls = explode("://", $item, 3);
if (count($urls) > 2)
{
$protocol = $matches[1][0];
$result[] = $protocol . "://" . $urls[2];
}
}
}
var_dump($result);
输出
array(4) {
[0]=>
string(83) "https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244"
[1]=>
string(83) "https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205"
[2]=>
string(16) "http://something"
[3]=>
string(15) "ftp://something"
}
答案 4 :(得分:0)
尝试
unset($setLinks[0]);
foreach($setLinks as $key) {
echo $key;
}
答案 5 :(得分:0)
我想念你的问题。请尝试一下
<?php $quest = array("https://www.proud-web.jp/mansion/b115110/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011244",
"https://www.proud-web.jp/mansion/p-ebisuminami88/https://www.proud-web.jp/module/structure/outline/BukkenOutline.xphp?code_no=011205");
foreach($quest as $q )
{
$allquest = explode("/https",$q);
echo "https".$allquest[1];
}
?>