mehidy1437 Posted March 14, 2023 Share Posted March 14, 2023 (edited) Hello guys, Please see below function, so far everything is good. But when I input Mehidy in input box, it's echo $name; it shows Mehidy, which is okay. But when I echo strlen($name); it shows 65 i/o 6 It's show the number of characters of $answer = "<script type='text/javascript'> document.write(answer); </script>"; why is it so? How can I get the real strlen of Mehidy? Please help. //prompt function function prompt($prompt_msg){ echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>"); $answer = "<script type='text/javascript'> document.write(answer); </script>"; return($answer); } //program $prompt_msg = "Please type your name."; $name = prompt($prompt_msg); echo $name; echo strlen($name); Edited March 14, 2023 by mehidy1437 Quote Link to comment Share on other sites More sharing options...
requinix Posted March 14, 2023 Share Posted March 14, 2023 You cannot mix PHP and Javascript like this: PHP runs on the server and has finished running by the time your browser starts to execute any of your Javascript. If you want the length of the string then you can get that in Javascript easily. What are you actually trying to do with this code? Quote Link to comment Share on other sites More sharing options...
mehidy1437 Posted March 14, 2023 Author Share Posted March 14, 2023 1 hour ago, mehidy1437 said: return($answer); Thanks for your response. $name is containing the string mehidy from the input & it's showing/printing fine. So, i just want to count the number of character in $name. If i can use the $name to print the string/input value then it should be possible to count the string length also, am I wrong here? Quote Link to comment Share on other sites More sharing options...
kicken Posted March 14, 2023 Share Posted March 14, 2023 3 hours ago, mehidy1437 said: $name is containing the string mehidy from the input & it's showing/printing fine. No, $name contains the Javascript code, which when later evaluated by the browser displays the value you typed in. Use you're browsers view-source command to see the code generated by your script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.