0

This is my orginal url. now I want to change %username% instead of $username.

$username = "abcd";

https://connectsms.vodafone.com.qa/SMSConnect/SendServlet?application=%username%&password=%password%&content=%message_text%&destination=%gsm%&source=%shortcode%&mask=%mask%

3
  • Very urgent anyone help me Commented Jan 18, 2020 at 6:59
  • could you add a simple of you're expect as result ? Commented Jan 18, 2020 at 7:22
  • Hi and welcome to SO! Please edit your question to clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. Commented Jan 18, 2020 at 8:26

3 Answers 3

1

Use the str_replace function.

$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);
Sign up to request clarification or add additional context in comments.

Comments

0

Just replace %username% instead of <?php echo $username ?>

 https://connectsms.vodafone.com.qa/SMSConnect/SendServlet?application=<?php echo $username ?>&password=%password%&content=%message_text%&destination=%gsm%&source=%shortcode%&mask=%mask%

Comments

0

Once you have the url, you can use str_replace() to put variables instead of certain strings.

$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

2 Comments

sir want to change the url parameters like username,password,content,message,destination,source,shortcode,mask etc. is it possible
Yes it is. You can add array for str_replace. Like: $new_url = str_replace(["%username%" , "%content%", "%message%" ... ], [$username, $content, $message], "http://"."$_SERVER[HTTP_HOST]"."$_SERVER[REQUEST_URI]"); Alternative way to save your variables in a key => value array and call foreach on it. like $url_params = [ '%username%' => $username, '%content%' => $content, ... ]; foreach($url_params as $search => $replace){ str_replace($search, $replace, "http://"."$_SERVER[HTTP_HOST]"."$_SERVER[REQUEST_URI]"); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.