Cod PHP impartire text pe linii
Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
-
bin_gal
- Mesaje:5
Cod PHP impartire text pe linii
Salut,
As vrea un sfat sau un indiciu cum asa putea transforma spre exemplu acest text:
Cod: Selectaţi tot
1. It was a week or two after the last whaling scene recounted 2. we were slowly sailing over a sleepy, 3. vapoury, mid-day sea, that the many noses on the Pequod's 4. vigilant discoverers than the three pairs of. 5. A peculiar and not very pleasant smelt in the sea.
In acesta:
Cod: Selectaţi tot
It was a week or two after the last whaling scene recounted
we were slowly sailing over a sleepy,
vapoury, mid-day sea, that the many noses on the Pequod's
vigilant discoverers than the three pairs of.
A peculiar and not very pleasant smelt in the sea.
Continutul intre doua cifre sa fie intr-un rand nou iar cifrele sa dispara. Nu vreau un script facut gata ci doar unele sfaturi cam cum l-as putea face. Multumesc.
MarPlo
Mesaje:4343
Salut
Incearca cu preg_replace(), sa inlocuiesti numerele urmate de punct cu un caracter de linie noua (" \n "), eventual cu tag HTML <br/> daca textul trebuie afisat in pagina web.
Uite exemplu:
Cod: Selectaţi tot
<?php
$str = '1. It was a week or two after the last whaling scene recounted 2. we were slowly sailing over a sleepy, 3. vapoury, mid-day sea, that the many noses on the Pequod\'s 4. vigilant discoverers than the three pairs of. 5. A peculiar and not very pleasant smelt in the sea.';
$str2 = preg_replace('/[ ]*[0-9]\.+[ ]*/i', "\n<br/>", $str);
echo $str2;
?>