cURL Попълване на форма и резултата

uphero

Registered
Здравейте, досега не ми се е налаго да работя с cURL и не се справих с задачата.
А тя е
http://bdz.bg/m/index.php
Да се попълни формата и после да се покажат резултатите от търсенето.
Пробвах с няколко скрипта за логин с Curl от форума но нещо не ми се получи
 
Заповявай : ) Връща ти HTMl-а на страницата като резултат. Ти трябва да си го преработиш за да ти върши работа резултата.

Код:
<meta http-equiv="content-type" content="text/html; charset=utf8">
<style>
* {
color: green;
background: black;
font-family: Verdana;
font-size: 11px; 
}

input {

background: green;
padding: 10px;
color: white;
border: 1px solid white;
font-size: 14px;
}

input:hover {
background: green;
color: silver;
border-color: silver;
}

hr {
  border: 1px solid green;
}

</style>

<form method="POST" action="">
  <input type="hidden" name="p" id="p" value="1">
    <input type="text" name="ot" id="ot" value="София"> От<br />
    <input type="text" name="do" id="do" value="Варна"> До<br />
  <input id="submit" name="submit" type="submit" value="Т Ъ Р С Е Н Е">
</form>

<?php
set_time_limit(0);


if (isset($_POST['p']) and $_POST['p'] == 1):

$exectime = microtime(); 
$exectime = explode(" ",$exectime); 
$exectime = $exectime[1] + $exectime[0]; 
$starttime = $exectime; 



 
    $post_data = array(
        'ot='.$_POST['ot'],
        'do='.$_POST['do'],
        'submit='.$_POST['submit']
    );
    
    $post_data = implode('&', $post_data);
    
    $url = 'http://bdz.bg/m/commit.php';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    ob_start();
    $res = curl_exec($ch);
    $result = ob_get_contents();
    ob_end_clean();
    ob_flush();
    set_time_limit(0);
    

 
echo $res;
 
   /* if (!eregi("съвпадат", $result)) {
     echo "<br /><br /><br /><hr />PASS DETECTED: $pwd";
        break;
        
    } */
    
    /* else {
     if($i % 10 == 0) {
      echo "<br />";
      }
      echo ". \n";
    }
    */
    





// put this at the bottom of your page/script
$exectime = microtime(); 
$exectime = explode(" ",$exectime); 
$exectime = $exectime[1] + $exectime[0]; 
$endtime = $exectime; 
$totaltime = ($endtime - $starttime); 


echo "<br />This page was created in ".$totaltime." seconds<hr/>";



endif;
?>
 
Благодаря,сега обаче ако могат да се махнат и линковете ще е супер
PHP:
$res = explode("<table>", $res);
$res = explode("</table>", $res[1]);
echo '<table width="100%">';
echo $res[0];
echo '</table>';
с explode си изкарах само таблицата но не се справих с линковете
пробвах така но не се получи
PHP:
echo $res[0] = preg_replace("#<a href='(.*)'>(.*?)</a>#" , '$2', $res[0]);
също и последния ред от таблицата ако има начин да се скрие ще е добре
в момента е
HTML:
<tr><th><a href = 'index.php'><img src='images/minGoback.png'/></a></th><td><a href = 'fare.php?ot=Тулово&do=Казанлък&dist=15&id1=5234000&id2=5232056'>Цени</a></td><td></td><th><a href = 'commit_reverse.php?id1=5234000&id2=5232056'><img src='images/minRefresh.png'/></a></th></tr>
 
абе дай го целия код де, че да си го copy paste и направо да редактирам :Д
 
PHP:
<ul> 
	<li><h2>БДЖ Разписание</h2>
	
<form method="POST" action="">
  <input type="hidden" name="p" id="p" value="1">
    <input type="text" placeholder="Начална гара" class="calc" name="ot" id="ot" >
    <input type="text" placeholder="Крайна гара" class="calc" name="do" id="do" >
	<center><button type="submit" name="submits4" value="" class="css3button">Т Ъ Р С Е Н Е</button></center>
</form>

<?php
set_time_limit(0);


if (isset($_POST['p']) and $_POST['p'] == 1):




 
    $post_data = array(
        'ot='.$_POST['ot'],
        'do='.$_POST['do'],
        'submit='.$_POST['submits4']
    );
   
    $post_data = implode('&', $post_data);
   
    $url = 'http://bdz.bg/m/commit.php';
   
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    ob_start();
    $res = curl_exec($ch);
    $result = ob_get_contents();
    ob_end_clean();
    ob_flush();
    set_time_limit(0);
   

$res = explode("<table>", $res);

$res = explode("</table>", $res[1]);

echo '<table width="100%">';

echo $res[0];
 

echo '</table>';




endif;
?>
	</li>
</ul>
[/code][/php]
 
Заповядай, използвах strip_tags :Р

Код:
<ul> 
        <li><h2>БДЖ Разписание</h2>
        
<form method="POST" action="">
  <input type="hidden" name="p" id="p" value="1">
    <input type="text" placeholder="Начална гара" class="calc" name="ot" id="ot" >
    <input type="text" placeholder="Крайна гара" class="calc" name="do" id="do" >
        <center><button type="submit" name="submits4" value="" class="css3button">Т Ъ Р С Е Н Е</button></center>
</form>

<?php
set_time_limit(0);


if (isset($_POST['p']) and $_POST['p'] == 1):




 
    $post_data = array(
        'ot='.$_POST['ot'],
        'do='.$_POST['do'],
        'submit='.$_POST['submits4']
    );
   
    $post_data = implode('&', $post_data);
   
    $url = 'http://bdz.bg/m/commit.php';
   
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    ob_start();
    $res = curl_exec($ch);
    $result = ob_get_contents();
    ob_end_clean();
    ob_flush();
    set_time_limit(0);
   

$res = explode("<table>", $res);
$res = explode("</table>", $res[1]);
$rs = $res[0];
echo '<table width="100%">';

$count = substr_count($rs, '<tr>');


for($i=1;$i<$count;$i++) {

$rss = explode("<tr>", $rs);
$rss = explode("</tr>", $rss[$i]);

echo "<tr>".strip_tags($rss[0], "<td>")."</tr>";

}


echo '</tr></table>';
 




endif;
?>
        </li>
</ul>
 

Back
Горе