kimseden cevap gelmeyince ve uğraşınca oldu belki başkar arakadaşlara yardımı dokunur

<?php


header('Content-Type: text/html; charset=utf-8');

function find_tag_content($start, $finish, $content)
{
    @preg_match_all('/'.preg_quote($start, '/').'(.*?)'.preg_quote($finish, '/').'/i', $content, $m);

    return @$m[1];
}
function find_tag_content2($start, $finish, $content)
{
    $first  = explode($start, $content);
    $result = explode($finish, $first[0]);

    return $result[0];
}

function replaceSpace($string)
{
    $string = preg_replace("/\s+/", " ", $string);
    $string = trim($string);
    $string = str_replace('\n', " ", $string);

    return $string;
}

$data = array();
$insertedIDs = array();
if($_POST)
{
    $host   = "localhost";
    $dbname = "botv1";
    $dbuser = "root";
    $dbpass = "";
    try
    {
        $db = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $dbuser, $dbpass);

        $table_exists = $db->query("SHOW TABLES LIKE 'firmalar';");
        if(!$table_exists)
        {
            die(print_r($dbh->errorInfo(), true));
        }
        if($table_exists->rowCount()==0)
        {
            $create_table_sql = "CREATE TABLE IF NOT EXISTS `firmalar` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `firma` varchar(255) NOT NULL,
  `telefon` mediumtext NOT NULL,
  `adres` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
            $db->exec($create_table_sql);
        }
    }
    catch(PDOException $e)
    {
        die($e->getMessage());
    }

    $link = $_POST["link"];

    $content = file_get_contents($link);
    $q       = explode('<td align="left" valign="center" width="60%" bgcolor="', $content);
    array_shift($q);
    $o = count($q);
    for($i = 0; $i<$o; $i++)
    {
        $ox                 = explode('</span>', $q[$i]);
        $ox                 = substr($ox[0], 11);
        $data[$i]["baslik"] = iconv('ISO-8859-9', 'UTF-8', strip_tags(replaceSpace($ox)));
    }

    $p = explode('<td align="left" valign="center" width="20%" bgcolor="', $content);
    array_shift($p);
    $s = count($p);
    $x = 0;
    for($i = 0; $i<$s; $i++)
    {
        if($i%2==0)
        {
            if($i!=0)
            {
                $x++;
            }
            $tel = $p[$i];
            $tel = explode('" />', $tel);
            $tel = str_replace(","," ",replaceSpace($tel[1]));

            $telefonlar = array();
            $telExp = preg_split('/<br[^>]*>/i', $tel);
            foreach($telExp as $tel)
            {
                $tel = trim(iconv('ISO-8859-9', 'UTF-8', strip_tags($tel)));
                if(strstr($tel,"/"))
                {
                    $telExp2 = explode("/",$tel);
                    foreach($telExp2 as $tel2)
                    {
                        $tel2 = trim($tel2);
                        if(!empty($tel2) && !strstr($tel2,"@"))
                            $telefonlar[] = $tel2;
                    }
                }
                else
                {
                    if(strstr($tel,"---"))
                    {
                        $telExp3 = explode("---",$tel);
                        foreach($telExp3 as $tel3)
                        {
                            $tel3 = trim($tel3);
                            if(!empty($tel3) && !strstr($tel3,"@"))
                                $telefonlar[] = $tel3;
                        }
                    }
                    elseif(!empty($tel))
                        $telefonlar[] = $tel;
                }
            }
            $tel = json_encode($telefonlar);

            $data[$x]["tel"] = $tel;
        }
        else
        {
            $adres = $p[$i];
            $adres = explode("<a", $adres);
            $adres = substr($adres[0], 11);
            $adres = replaceSpace($adres);

            if($i==39)
            {
                $adres = explode("<b>", $adres);
                $adres = substr($adres[0], 0, -2);
            }

            $data[$x]["adres"] = iconv('ISO-8859-9', 'UTF-8', strip_tags($adres));
        }
    }

    if(!empty($data))
    {
        foreach($data as $satir)
        {
            $sql_data = array(
                $satir["baslik"],
                $satir["tel"],
                $satir["adres"],
            );

            $insert = $db->prepare("INSERT INTO firmalar (firma,telefon,adres) VALUES (?,?,?)");
            if($insert->execute($sql_data))
                $insertedIDs[] = $db->lastInsertId();

            $hata = $insert->errorInfo();
            if(!empty($hata[2]))
            {
                echo $hata[2];
                die();
            }
        }
    }
}
?><!DOCTYPE html>
<html>
<head>
    <title>Bot v1</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <form action="" method="post" class="text-center" style="width:400px;margin:200px auto">
        <div class="form-group">
            <input type="text" name="link" class="form-control" value="" placeholder="Lütfen link giriniz" required> <input style="margin-top:20px;" type="submit" value="Verileri Çek ve Kaydet" class="btn btn-block btn-primary">
        </div>
    </form>

    <div class="">
        <?php if(!empty($data))
        { ?>
            <h3 class="text-center"> Sonuçlar : Veritabanına <?=count($insertedIDs)?> kayıt eklendi</h3>
            <table class="table table-striped">
                <tr>
                    <th>#</th>
                    <th>Firma</th>
                    <th>Telefon</th>
                    <th>Adres</th>
                </tr>
                <?php foreach($data as $i => $row)
                { ?>
                    <tr>
                        <td><?=++$i?></td>
                        <td><?=$row['baslik']?></td>
                        <td><?=$row['tel']?></td>
                        <td><?=$row['adres']?></td>
                    </tr>
                <?php } ?>
            </table>
            <?php
        } ?>
    </div>
</div>
</body>
</html>