亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

str_replace 中的空間問題

str_replace 中的空間問題

PHP
搖曳的薔薇 2022-10-22 15:58:57
我為圖像 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


查看完整回答
反對 回復 2022-10-22
  • 1 回答
  • 0 關注
  • 94 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號