-
Posts
49 -
Joined
-
Last visited
Everything posted by cataiin
-
It's just an example. I want to know how to send multiple queries - in my case. Thanks.
-
This creates the table and inserts only one row. After refresh, no change. But if I replace $query .= with $query = and then refresh page (after first row was inserted), I get all rows, but first one duplicated. How I can fix this - to create all rows from first time when the code is executed? $url = file_get_contents('http://lorem.ipsum'); preg_match_all('|href/(tt\d+)|i', $url, $id); preg_match_all('|<div id=aba>([^<]*)</div>|i', $url, $date_and_text); $count = count($date_and_text[1]) - 1; for ($i=0; $i <= $count; $i++) { $date = substr($date_and_text[1][$i], 0, ; $text = substr($date_and_text[1][$i], 22); $tomorrow = date('d.m.Y', strtotime('+1 day')); $query = "CREATE TABLE `".$tomorrow."` (id varchar(255), date varchar(255), text varchar(255));"; $query .= "INSERT INTO `".$tomorrow."` VALUES ('{$id[1][$i]}', '{$date}', '{$text}')"; $send_to_mysql = mysqli_multi_query($connection, $query); }
-
Aww, thanks. strstr return what I want, but only one result and I need all of them. I need to find all data between http://www.imdb.com/title/ and "> and save them to MySQL.
-
I have this code: $url = file_get_contents('http://lala.com'); $before_imdb_url = 'http://www.imdb.com/title/'; $after_imdb_url = '">'; $imdb_url = strstr(substr($url, strpos($url, $before_imdb_url) + strlen($before_imdb_url)), $after_imdb_url, true); var_dump($imdb_url); ...result: string(15) "tt119247" ...and two questions: 1. is in my case best (and fastest) way to use strstr or should I use something else - and what? 2. my code returns only one result, but there's more. I've tried with foreach but no succes: foreach ($imdb_url as $a) { echo $a; } what should I do?
-
Nobody? If you don't understand please ask, my english is kinda bad.
-
Hello. I have a (big) text and a JSON file containing url needed. But execution time is toooo long. $texts returns string(50) "Lorem ipsum dolor sit amet, consectetur adipiscing" string(50) "elit. Cras diam velit, lobortis nec fermentum id, " string(46) "congue nec nibh. Pellentesque pretium, dui ut." $text_encode = rawurlencode($texts); $url_address = @file_get_contents('http://api.url/?text='.$text_encode); http://api.url/?text=something it's a JSON result. So I use this to select and get .mp3 file: $before_address = '"url":"'; $after_address = '","format"'; $address = strstr(substr($url_address, strpos($url_address, $before_address) + strlen($before_address)), $after_address, true); $mp3 = @file_get_contents($address); and to save... $part = 1; $files = 'audio/parts/'.md5($mp3).'-'.$part.'.mp3'; $file_final = '/audio/'.md5($mp3)'.mp3'; $save_mp3 = file_put_contents($files, $mp3); $save_mp3_final = file_put_contents($file_final, $mp3, FILE_APPEND); It's file_get_contents a bad practice in both cases? Or file_put_contents used two times? What should I use to retrieve data faster...? Thanks. I've been thinking about json_decode and cURL, but never used and I don't know if it's best method to solve my problem.
-
how can i give text HTML formatting after a usser subits a form
cataiin replied to Baxt01's topic in PHP Coding Help
Yes, you're right! My mistake, sorry. -
how can i give text HTML formatting after a usser subits a form
cataiin replied to Baxt01's topic in PHP Coding Help
<form method="post"> <textarea name="textarea"></textarea> <input type="submit" /> </form> <?php $file = "text.txt"; $text = $_POST["textarea"]; $text_ok = nl2br($text); file_put_contents($file, $text_ok); include "text.txt"; ?> -
Ah, sorry. Then I saw you already use nl2br. Try to replace: <p><?php echo stripslashes(nl2br($reply->content)); ?></p> with: <p><?php echo nl2br(stripslashes($reply->content)); ?></p>
-
http://php.net/manual/en/function.nl2br.php
-
with preg_match: if(preg_match("/$word/", $target)) { echo "Exists."; } else { echo "Nop."; } sorry but then I saw you want with preg_match.
-
if(strpos($target, $word) !== false) { echo "Exists."; } else { echo "Nop."; }
-
what returns: echo "<a href='".$modelurl.$item['performerid'].$modelpagenext."'><img src='".$file."' width='160px' height='120px' border='0px' alt='' /></a>"; ?
-
try: echo "<img src='".$file."' width='160px' height='120px' border='0px' alt='' />"; echo "<a href='".$modelurl.$item['performerid']."'>".$modelpagenext."</a>";
-
$where = "path/"; chdir($where); array_multisort(array_map('filemtime', ($files = glob("*.*"))), SORT_DESC, $files); var_dump($files);
-
http://mobiledetect.net/
-
No, it does not help me. I have to use file_put_contents. Otherwise, the code does not work.
-
Thanks for replies. I'm allowed to extract data from the site, only $text must be limited to 25 characters. Following code does exactly what I want: $txt = file_get_contents("http://example.org/text=".$text_ok); $file = "texts/parts/".md5($text)."-".$number.".txt"; $file_final = "texts/".md5($text).".txt"; if(!file_exists($file)) { file_put_contents($file, $txt); file_put_contents($file_final, $txt, FILE_APPEND); } I do not know how accurate it is but it's the only solution I've found it... Is no problem with: $file = "texts/".md5($text)."-".$number.".txt"; Result is always different and content also. I hope I get it right!
-
Look, for example this code: $text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae tortor odio. Proin ac enim a orci consectetur venenatis. Nunc metus nunc, convallis eget tincidunt sit amet, suscipit in urna. Maecenas imperdiet vestibulum malesuada. Nulla quis pharetra neque. Nunc a erat interdum, dictum metus in, dignissim orci."; $text_split = str_split($text, 25); $number = 1; foreach($text_split as $texts) { $text_ok = urlencode($texts); if(!@file_get_contents("http://example.org/?q=".$text_ok)) { echo "Error."; } else { $txt = file_get_contents("http://example.org/?q=".$text_ok); $file = "texts/".md5($text)."-".$number.".txt"; file_put_contents($file, $txt); } $number++; } Create texts/eebb32402578e0ce1297b8c2bbac056e-1.txt, texts/eebb32402578e0ce1297b8c2bbac056e-2.txt etc. Different files with different content. Everything is correct. I only need them "combined" into a single file and I thought to appeal to FILE_APPEND for it because I thought it was easier and escape $number too. And first code do this, makes eebb32402578e0ce1297b8c2bbac056e.txt with content from all files with the same name. But it doubles each time. Sorry but my english is so bad. Hope you understand.
-
Is this better: $text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae tortor odio. Proin ac enim a orci consectetur venenatis. Nunc metus nunc, convallis eget tincidunt sit amet, suscipit in urna. Maecenas imperdiet vestibulum malesuada. Nulla quis pharetra neque. Nunc a erat interdum, dictum metus in, dignissim orci."; $text_split = str_split($text, 25); $number = 1; foreach($text_split as $texts) { $text_ok = urlencode($texts); if(!@file_get_contents("http://example.org/?q=".$text_ok)) { echo "Error."; } else { $txt = file_get_contents("http://example.org/?q=".$text_ok); $file = "texts/".md5($text)."-".$number.".txt"; file_put_contents($file, $txt); } $number++; } ? But how to combine the results now?
-
How to detect URL extensions (like ?this=value) in PHP
cataiin replied to RavinduL's topic in PHP Coding Help
$code = $_GET["code"]; echo $code; on index.php. -
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae tortor odio. Proin ac enim a orci consectetur venenatis. Nunc metus nunc, convallis eget tincidunt sit amet, suscipit in urna. Maecenas imperdiet vestibulum malesuada. Nulla quis pharetra neque. Nunc a erat interdum, dictum metus in, dignissim orci."; $text_split = str_split($text, 25); foreach($text_split as $texts) { $text_ok = urlencode($texts); if(!@file_get_contents("http://example.org/?q=".$text_ok)) { echo "Error."; } else { $txt = file_get_contents("http://example.org/?q=".$text_ok); $file = "texts/".md5($text).".txt"; file_put_contents($file, $txt, FILE_APPEND); } } Thanks for replies. I already tried with LOCK_EX. Same result.
-
I have this: $txt = file_get_contents("http://example?a=".$text); $file = "texts/".md5($text).".txt"; file_put_contents($file, $txt, FILE_APPEND); and everything is okay. Except when I access the file again, $file values are doubled. So I try to add if(!file_exists($file)): $txt = file_get_contents("http://example?a=".$text); $file = "texts/".md5($text).".txt"; if(!file_exists($file)) { file_put_contents($file, $txt, FILE_APPEND); } but that does not work, now FILE_APPEND containing only the first $txt values, not all. I hope you understand. Thanks.