Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have link .
http://www.example.com/about
$_SERVER['REQUEST_URI'] is /about.
So when I do
preg_match("/about/i",$_SERVER['REQUEST_URI']),
it matches the about link.
But if I have to match www.example.com, then I saw that $_SERVER['REQUEST_URI'] returns /.
So I used this code
preg_match("/\//i",$_SERVER['REQUEST_URI']),
but it dosent work. Why?What is the correct solution to preg match /?
You are looking in the wrong variable. $SERVER['REQUEST_URI'] only gives you the relative name of the request, so in your example you will only get "/about". To get the domain name, use the superglobal $SERVER['SERVER_NAME'];.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
a challenge like this $_GET['2020'] snippet boring me a long time, i want to know how this work, but do not know which keywords to search, maybe how the parameter works?
$_GET reads querystring parameters from the URL. So if someone goes to your PHP script with a URL like http://servername/scriptname.php?2020=ABC then when the PHP script runs, the variable $_GET['2020'] will contain the value ABC.
More info is available in the documentation: https://www.php.net/manual/en/reserved.variables.get.php
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I changed the Permalink on WP to get any strings after the path. I use the regex: "yourdomain.com/%postname%-(.*)/"
When I am checking: "yourdomain.com/%postname%-f46eb54b99ce3a9835ea7d63e075d434", it matches.
But when I check:
"yourdomain.com/%postname%-446eb54b99ce3a9835ea7d63e075d434" then it returns "yourdomain.com/%postname%-(.*)/446/".
I think (. *) Will fit in everything, regardless of letters or numbers. I appreciate anyone who can explain it to me.
You should escape all / and ., if you mean them as normal symbols. So, you'll have:
yourdomain\.com\/%postname%-(.*)\/
It must not match
yourdomain.com/%postname%-f46eb54b99ce3a9835ea7d63e075d434
or
yourdomain.com/%postname%-446eb54b99ce3a9835ea7d63e075d434
, because you regex demands / at the end. If it is not obligatory, put ? after the ending \/.
yourdomain\.com\/%postname%-(.*)\/?
tests
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have to get something that has been shared on a website and it changes every day. but i dont know how to do this. how can i do this?
You could download the exact page you're after using file_get_contents
$web = file_get_contents("http://google.com")
You'd then have to strip out whatever it is you want from the rest of the source code on the website. That can be done by using strpos or stripos (ipos being case insensitive) to find its location, and then using substr to extract that part of the string.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a PHP script which accepts some query string parameters. However, I want the user to call it without including the script name e.g. example.com/?foo=bar.
I've tried writing a mod_rewrite rule, but it redirects the user, which isn't what I want.
If you rename the script to index.php, accessing example.com/?p=asd&p2=dsa should work.
For the RewriteRule, make sure you don't have [R] after it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I used the following code to get the file contents:
$file_contents = file_get_contents('note.txt');
Then i used preg_match_all to get some matches.
What is the problem then ?
The problem is if the file format of note.txt is not set to UNIX, preg_match_all will not match anything whatever is the file encoding is!
Your regular expression doesn't account for windows EOL, or OSX EOL. Below is a fix for it.
\A[\r\n]+\/\*[\r\n]+(([^:\r\n]*:[^\r\n;]*[\r\n]+)+)