Link to home
Start Free TrialLog in
Avatar of thenelson
thenelson

asked on

str_replace not working in php script

I have a line in a php script that is working fine:
document.getElementById("tocall").value = $_GET["number"];
When I change it to:
document.getElementById("tocall").value = str_replace("tel:", "", $_GET["number"]);
The line does not work: the field "tocall" does not get filled in and lines after that line do not run.
I get no error messages. I cannot figure out what is wrong.
echo str_replace("tel:", "", "1234"); works fine in an online php emulator but it doesn't work in my script.

Perhaps you can see something I missing?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please post a URL link to this web page so we can use "view source" to see the same thing the browser is seeing, thanks.
Avatar of thenelson
thenelson

ASKER

You're right. It's been quite a while since I worked with php, favascript and html in the same file so I didn't see this is javascript. Thanks for the dope slap.

So I changed php str_replace to java:
document.getElementById("tocall").value = $_GET["number"].replace("tel:", "");
still didn't work. Then I tried:
var str =  $_GET["number"];
document.getElementById("tocall").value = str.replace("tel:", "");
still didn't work.

Here is the code around that line:
<script type="text/javascript">
...

window.onload=setTimeout(function StartFunction()
            {
                  var $_GET = <?php echo json_encode($_GET); ?>;
                  if (typeof($_GET["number"]) != "undefined" && $_GET["number"] !== null)
                  {
                     document.getElementById("tocall").value = $_GET["number"];
                     document.getElementById("call").click();
                  }
                  if (typeof($_GET["digits"]) != "undefined" && $_GET["digits"] !== null)
                  {
                     document.getElementById("digits").value = $_GET["digits"];
                  }
            }, 1000)
            
            </script>
>Please post a URL link to this web page so we can use "view source" to see the same thing the browser is seeing, thanks.
It's a php script so you won't be able to see it. It's also in a secured folder.  But i did post a section of the code.