1

私は次のコードを持っています。

<?php
$text = "text"; $text_ok = urlencode($text);
if(!@file_get_contents("http://site.com/t=".$text_ok))
{
    echo "Error.";
}
else
{
    $data = file_get_contents("http://site.com/t=".$text_ok);
    $file = "texts/".md5($text).".txt";
    if(!file_exists($file)) {
        file_put_contents($file, $data);
    }
?>
Lorem <?php echo $file; ?>"> ipsum
<?php
}
?>

問題は、が 25 文字未満のhttp://site.com/t=$text_ok場合にのみ機能することです。25文字を超える場合、複数に分割して などのファイルを作成すること$textは可能でしょうか。ご理解いただければ幸いです。どんな助けでも大歓迎です。ありがとう!$texttexts/md5($text)/1.txttexts/md5($text)/2.txt

4

1 に答える 1

1

これを試して:

<?php
$text = "text";
$split = str_split($text, 25);
$count = 1;
foreach ($split as $s) {
    $text_ok = urlencode($s);
    if (!@file_get_contents("http://site.com/t=" . $text_ok)) {
        echo "Error.";
    } else {
        $data = file_get_contents("http://site.com/t=" . $text_ok);
        $file = "texts/" . md5($text) . "/" . $count . ".txt";
        if (!file_exists($file)) {
            file_put_contents($file, $data);
        }
        ?>
        Lorem <?php echo $file; ?>"> ipsum
        <?php
    }
    $count++;
}
?>
于 2013-09-13T13:23:15.193 に答える