Q:

How to filter data from a connection string in php

I have the following connection string and have this standard syntax always.
mysql:host=localhost;port=3306;dbname=mydb
Is there an easy way to filter the information(host, port,dbname) to a php variable?

A:

You can use parse_str and str_replace to do the trick.
<?php
$str='mysql:host=localhost;port=3306;dbname=mydb';
parse_str(str_replace(';','&',$str),$arr);
print_r($arr);

OUTPUT :
Array
(
    [mysql:host] => localhost
    [port] => 3306
    [dbname] => mydb
)

