tags:

views:

28

answers:

1

I'm trying to use preg_match to extract info from

href="domain.com/subdir/?key=value

The info I want are

  1. domain.com
  2. subdir
  3. key
  4. value

Can someone suggest what is the correct way to write the preg_match statement?

Thanks!

A: 

use this as your regex

/href="(.+..+?)\/(.+?)\/(\?.+?=.+)"/

that should work

preg_match('/href="(.+\..+?)\/(.+?)\/(\?.+?=.+)"/', $input, $matches);
echo "First Match: {$matches[0]}\n";
Mimisbrunnr
Is this how it should be written?$test = "href='domain.com/subdir/?key=value'";preg_match("/href='(.+\..+?)\/(.+?)\/(\?.+?=.+)'/", $test, $match);echo $matches[0];echo $matches[1];Doesn't seem to work though.
John Adawan
New form should work.
Mimisbrunnr
My error. Yes it worked. Thanks!
John Adawan