用php中的变量替换url参数

芜湖不芜
浏览 250回答 3
3回答

回首忆惘然

使用 str_replace 函数。$url = "https://connectsms.vodafone.com.qa/SMSConnect/SendServlet?application=%username%&password=%password%&content=%message_text%&destination=%gsm%&source=%shortcode%&mask=%mask%";//define variables$username = "abcd";//then$before = ["%username%","%password%"];$after = [$username,$password];$output = str_replace($before,$after,$url);

拉莫斯之舞

获得 url 后,您可以使用 str_replace() 来放置变量而不是某些字符串。$new_url = str_replace("%username%" , $username, "http://"."https://connectsms.vodafone.com.qa/SMSConnect/SendServlet?application=%username%&password=%password%&content=%message_text%&destination=%gsm%&source=%shortcode%&mask=%mask%");https://www.php.net/manual/en/function.str-replace.php

Qyouu

只需替换%username%而不是<?php echo $username ?>&nbsp;https://connectsms.vodafone.com.qa/SMSConnect/SendServlet?application=<?php&nbsp;echo&nbsp;$username&nbsp;?>&password=%password%&content=%message_text%&destination=%gsm%&source=%shortcode%&mask=%mask%
打开App,查看更多内容
随时随地看视频慕课网APP