我为图像 crwaler 制作了一个 wordpress 插件,但我在这段代码中有问题所以当我打印 $image 我得到这个输出 https://localhost/wordpresshttps://后面有个空格我试过 str_replace 但没有走我想要结果https://localhost/wordpress<?php function image_url_filter($url) { $url = str_replace('?ssl=1', '', $url); $url = str_replace('https://', '', $url); $url = str_replace('http://', '', $url); $url = str_replace('//', '', $url); $url = str_replace('http:', '', $url) return "https://{$url}"; } function get_chapter_images() { include('simple_html_dom.php'); $url = 'http://localhost/wordpress/manga/manga-name-ain/chapter-4/'; $html = file_get_html($url); $images_url = array(); foreach ($html->find('.page-break img') as $e) { $image_links = $e->src; array_push($images_url, image_url_filter($image_links)); } //print_r($images_url); return $images_url; } $images_links = get_chapter_images(); foreach ($images_links as $image) { print_r($image); }
1 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
%09并且+意味着您的字符串中同时包含taband space,因此您需要使用urldecode(),str_replace()来解决这个问题:
<?php
$url = 'https%3A%2F%2F%09%09%09+%09%09%09localhost%2Fwordpress%2Fwp-content%2Fuploads%2FWP-manga%2Fdata%2Fmanga_5e62092804a6d%2Ff6954e41130c0015b5b89a3021d55595%2F12.jpg';
$url_decode = urldecode($url);
$url_decode = str_replace(" ", "", $url_decode);
$url_decode = str_replace("\t", "", $url_decode);
echo $url_decode;
输出:
https://localhost/wordpress/wp-content/uploads/WP-manga/data/manga_5e62092804a6d/f6954e41130c0015b5b89a3021d55595/12.jpg
tab注意:替换或替换时不要忘记使用双倍配额newline
- 1 回答
- 0 关注
- 60 浏览
添加回答
举报
0/150
提交
取消