PHP: Extracting Specified String

This example, we will see how to extract the particular string mentioned in the preg_match first parameter from the selected string

The below is the code for the same,

preg_match(“/^(http:\/\/)?([^\/]+)/i”,”“, $matches);
$host = $matches[2];
echo $host;

 Output is :   

The second example illustrate the string extracting  “” from the string  $host, the code and output will be as below,

echo “domain name is: “.$matches[0].”\n”;

Output is:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: