質問

私のような不思議なものとして私にとってはnead私のテキストformating.なお尋ねくださいのはなぜかったので気になることができます。;-)

なので、私のPHPスクリプトに置き換えてラインfoldings" "の特別シンボルのように"|".私はテキスト入力モードにデータをデータベースのPHPスクリプトに置き換えてラインfoldingsのシンボル"|"の場合、スクリプトを読み込みのテキストデータからのデータベースで置換すべて半角カタカナや特殊記号は"|"を折れ線" "

い限りテキスト形式でのネットラインfoldingsが複数の場合は2線foldingsそれぞれ分離します。

この例では、テキストに当たって、スクリプトのフォーマット:

this is text... this is text... this is text...this is text...this is text... this is text... this is text... this is text... this is text... this is text...

this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text...

いrestictフォルト:

this is text... this is text... this is text...this is text...this is text... this is text... this is text... this is text... this is text... this is text...



this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text...

なので、初めての例であるラインの折り畳みの間に2つのテキストの例が3ラインfoldings2。

に関する詳細については交換が可能2線foldings字"|"の場合検出された、テキストを使うことができます。

このような例に当たって、スクリプトスポット:

    $text = str_replace("|||", "||", $text);
    $text = str_replace("||||", "||", $text);
    $text = str_replace("|||||", "||", $text);
    $text = str_replace("||||||", "||", $text);
    $text = str_replace("|||||||", "||", $text);
    ...
    $text = str_replace("||||||||||", "||", $text);

    $text = str_replace("|", "<br>", $text);

HMしています。これは動作しない場合テキストデータを送信した後の方法です。この:

//REPLACING ALL LINE FOLDINGS WITH SPECIAL SYMBOL
$_POST["text"] = str_replace("\n","|",$_POST["text"]);
// REMOVING ALL LINE FOLDINGS
$_POST["text"] = trim($_POST["text"]);
// IF THERE ARE MORE THAN 3 LINE HOLDINGS - FORMAT TO 1 LINE HOLDING
$_POST["text"] = preg_replace("/\|{3,}/", "||", $_POST["text"]);
echo $_POST["text"];

こちらはテキストを入力しにtextareaのstr_replaceです:

This is text 1. This is text 1. This is text 1. This is text 1. This is text 1. This is text 1. This is text 1. | | |This is text 2. This is text 2. This is text 2. This is text 2. This is text 2. This is text 2. This is text 2. | | | |This is text 3. This is text 3. This is text 3. This is text 3. This is text 3.

こちらは自PHPとHTMLコード:

<?
//REPLACING ALL LINE FOLDINGS WITH SPECIAL SYMBOL
$_POST["text"] = str_replace("\n","|",$_POST["text"]);

echo "1) ".$_POST["text"]."<br><br>";

// REMOVING ALL LINE FOLDINGS
$_POST["text"] = trim($_POST["text"]);
// IF THERE ARE MORE THAN 3 LINE HOLDINGS - FORMAT TO 1 LINE HOLDING
$_POST["text"] = preg_replace("/\|{3,}/", "||", $_POST["text"]);

echo "2) ".$_POST["text"]."<br><br>";
?>
<html>

<head>
<title>No title</title>
<meta name="generator" content="Namo WebEditor v5.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<form name="form1" method="post" action="test.php">
    <p><textarea name="text" rows="8" cols="55"></textarea></p>
    <p><input type="submit" name="formbutton1"></p>
</form>
<p>&nbsp;</p>
</body>

</html>
役に立ちましたか?

解決

は、正規表現を使用するには良い場所のように思えます

$text = preg_replace('/\|{3,}/', '||', $text);

英語: "|で3つの以上の||文字を置き換え"

他のヒント

function clean($content) {
    $content = str_replace("||","|",$content);
    if (stripos("||",$content) !== false) {
        $content = clean($content);
    }

    return $content;
}

$text = clean($text);

ループ機能のようなもの。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top