Answer the question
In order to leave comments, you need to log in
How to avoid Illegal characters found in URL error with curl?
Hello everyone, I've run into a problem.
Wanted to create a way to send urls directly from a text file to curl .
But there was an error Illegal characters found in URL . How to fix?
Here is the code
<?php
echo '<form action="" method="post" >';
echo 'Сайт';
echo '<input class="url" type="text" name="urlsite" size="10" value="';
?>
<?php
$show_info = file('mes.txt');
echo $show_info[0];
?>
<?php
echo '" />';
echo 'Описание';
echo '<input class="text" type="text" name="text" size="10" value="';
?>
<?php
echo $show_info[1];
?>
<?php
echo '" />';
echo '<input type="submit" name="Button" value="добавить" />';
echo '</form>';
if (!empty($_POST)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $show_info[2]);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'urlsite' => $_POST['urlsite'],
'text' => $_POST['text'],
'Button' => 'get'
));
curl_setopt($ch, CURLOPT_USERAGENT, 'MSIE 5');
curl_setopt($ch, CURLOPT_REFERER, "http://ya.ru");
$res = curl_exec($ch);
if (!$res) {
$error = curl_error($ch) . '(' . curl_errno($ch) . ')';
echo $error;
} else {
if (preg_match("/\<table class\='yaResultat'(.+)\<\/table\>/isU", $res, $found)) {
$content = $found[0];
echo $content;
} else {
echo '<form></form>';
}
}
curl_close($ch);
}
if (!empty($_POST)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $show_info[3]);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'urlsite' => $_POST['urlsite'],
'text' => $_POST['text'],
'Button' => 'get'
));
curl_setopt($ch, CURLOPT_USERAGENT, 'MSIE 5');
curl_setopt($ch, CURLOPT_REFERER, "http://ya.ru");
$res = curl_exec($ch);
if (!$res) {
$error = curl_error($ch) . '(' . curl_errno($ch) . ')';
echo $error;
} else {
if (preg_match("/\<table class\='yaResultat'(.+)\<\/table\>/isU", $res, $found)) {
$content = $found[0];
echo $content;
} else {
echo '<form></form>';
}
}
curl_close($ch);
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question