Langen Text (variable und in nur einer Zeile) lesbar formatieren

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Langen Text (variable und in nur einer Zeile) lesbar formatieren

    Hi,
    ich habe verschiedene Text die alle in nur einer Zeile stehen = nicht gerade gut lesbar :/

    Bsp.:
    On the other hand, we denounce with righteous indignation and
    dislike men who are so beguiled and demoralized by the charms of
    pleasure of the moment, so blinded by desire, that they cannot foresee
    the pain and trouble that are bound to ensue; and equal blame belongs to
    those who fail in their duty through weakness of will, which is the
    same as saying through shrinking from toil and pain. These cases are
    perfectly simple and easy to distinguish. In a free hour, when our power
    of choice is untrammelled and when nothing prevents our being able to
    do what we like best, every pleasure is to be welcomed and every pain
    avoided. But in certain circumstances and owing to the claims of duty or
    the obligations of business it will frequently occur that pleasures
    have to be repudiated and annoyances accepted. The wise man therefore
    always holds in these matters to this principle of selection: he rejects
    pleasures to secure other greater pleasures, or else he endures pains
    to avoid worse pains.On the other hand, we denounce with righteous
    indignation and dislike men who are so beguiled and demoralized by the
    charms of pleasure of the moment, so blinded by desire, that they cannot
    foresee the pain and trouble that are bound to ensue; and equal blame
    belongs to those who fail in their duty through weakness of will, which
    is the same as saying through shrinking from toil and pain. These cases
    are perfectly simple and easy to distinguish. In a free hour, when our
    power of choice is untrammelled and when nothing prevents our being able
    to do what we like best, every pleasure is to be welcomed and every
    pain avoided. But in certain circumstances and owing to the claims of
    duty or the obligations of business it will frequently occur that
    pleasures have to be repudiated and annoyances accepted. The wise man
    therefore always holds in these matters to this principle of selection:
    he rejects pleasures to secure other greater pleasures, or else he
    endures pains to avoid worse pains
    Meine Idee ist nun mit hilfe von PHP nach den Punkten <br/> zu adden.
    Am besten wäre: - setzte <br /> nach X Sätzen.

    X = random Zahl zwischen 2-4

    Hat jemand eine Idee wie ich das in PHP umsetzen kann?
    Freue mich über jede Antwort :)
  • Source Code

    1. $datei = file("./text.txt");
    2. for($a = 0; $a < sizeof($datei); $a++){
    3. if(rand(2,4)){
    4. print $datei[$a]."<br />";
    5. }else {
    6. print $datei[$a];
    7. }
    8. }


    Bisher hab ich das nach 2-4Zeilen ein <br > einzusetzen so gemacht, nach Punkt müsste ich nochmal nachgucken aber das dürfte dir fürs erste helfen =)

    mfG s1ck
  • Naja, hier Variante 1

    Source Code

    1. // replace existing linebreaks through spaces
    2. $text = preg_replace("/[\r\n]?\n/", ' ', $text);
    3. // replace sentence end (dot, questionmark, ...) followed by space
    4. $text = preg_split('/[\.\?!] /', $text);
    5. foreach($text as $i => $sentence) {
    6. echo $sentence;
    7. if ($i % 4 == 0) {
    8. echo '<br />';
    9. }
    10. }
    Display All


    Variante 2 wäre eher eine Spielerei gewesen ;)