Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- How to blend adsense inside your post?
- PHP: add a download as pdf file button in report page
- Formatting my post
- Notepad++ - Add C++ compiler
- PHP connect IBM db2 database in XAMPP
- Datatable export excel wraptext and newline
- phpexcel toggle expand and hide column in EXCEL and summary
- Sweet Alert JS library - beautiful replacement of JavaScript Alert
- ActionScript 3.0 demo: create a falling snow in flash CS6
Wednesday, June 19, 2013
To get query string of URL in PHP and JavaScript
To get query string of a url in PHP, we use $_GET, for example test1.php
<?php
echo htmlspecialchars($_GET["name"]);
?>
test1.php?name=jiansen&name1=andy will return jiansen
For javascript, we use document.location.search.substring
for example test2.html
<html>
<script>
q=document.location.search.substring(0);
document.write(q);
document.write("<p>")
q1=document.location.search.substring(1);
document.write(q1);
document.write("<p>")
a=new Array();
a=q1.split('&');
document.write(a[0]);
</script>
</html>
Using test2.html?name=jiansen&name1=andy,
the following picks up the ENTIRE query string including the leading question (?) mark:
q=document.location.search.substring(0);
i.e.we got ?name=jiansen&name1=andy
To skip the question mark:
q1=document.location.search.substring(1);
i.e.we got name=jiansen&name1=andy
Either way, then you have to parse the string:
a=new Array();
a=q1.split('&');
For first element in array, we got
name=jiansen
Subscribe to:
Post Comments (Atom)
thanks alot! working for me
ReplyDelete