Formatting Text

Hello Experts ,

i have a text format in the DB i want to query the text then i want to do some Formating in the text ,

when i want to do this with my little experience is very hard ..

i try to do like this :
  str_replace

but its very hard for me for formating large text .. my text its change its not one ,,
can i choose my be from first line to 10 lines but it in the table or change the color
Do you have any idea forwhat is the best thing to formating text ..
my text is :
============================
Changes to GPs' opening hours will come into force from April, and could mean an average sized practice opening an extra three hours per week.
1             2              3
3              5             4
8          4                                        10
Ministers want more surgeries open at weekends and in the evenings, but the BMA had previously warned daytime services could be harmed by the changes.
====================
the above example is the just example i put some text together the important things is that the numbers 1       2      3 how could i formatting it by put each number in 1 line and do some change colors ..
thanx in advance
CFIL
CFILAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dr_dedoCommented:
you should provide some pattern hee, as will there always bee a line, 3 lines of numbers each containing 3 digits separated by tabs or multiple spaces ?
a pattern is something you need to define before trying to code what you need
0
CFILAuthor Commented:
hi ,
i don't have exact text , because i got lots of text files ,, maybe all files same as this
1             2              3
3              5             4
8          4                                        10

is there any way may be i do like that in the line 3 , the first entry which is here "1" put the color blue
the second one in the same line which is "2" put the color green . like this ..

there is space between the numbers .

thank you for your reply.
CFIL
0
ChorchCommented:
An easy but usefull code for this.

Put/get your text into a variable, then:

$yourtext = str_replace('1', '<font color=\"#FF0000\">1</font>', $yourtext);
$yourtext = str_replace('3', '<font color=\"#545454\">2</font>', $yourtext);
etc...
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

CFILAuthor Commented:
Chorch  , yeah i could do that and i said i can used
str_replace

but if the text is random ? maybe the first textis 1 the second text is 5 ? but the total lines and space are the same .
in this case i guess i must used somethings with lines , maybe in line 4 do that ,,, but i don't know how ?

CFIL
0
CFILAuthor Commented:
any idea Experts !!
0
dr_dedoCommented:
try this, i assign a class to each number so, you should have 3 classes ready
<?
$data = <<<DATA
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
1             2              3
3              5             4
8          4                                        10
8          4                                        10
8          4                                        10
DATA;
$x = preg_replace('/(\d+)\s+(\d+)\s+(\d+)/','
<br><span class="style1_1">$1</span>
<span class="style1_2">$2</span>
<span class="style1_3">$3</span>
',$data);
echo $x;
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CFILAuthor Commented:
Perfect ,, it work grate like what i want ,,

i it like the code below it work fine ,, but how can choose which line i want ?
i have seen its start from the numbers even if i change the number 1 to 5 in the start .. is there any way to choose in which line or do you have any reference could read and understand deeply about the function you are used ..

thank you ..
<?
$data = <<<DATA
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
 
1             2              3
3              5             4
8          4                                        10 
8          4                                        10
8          4                                        10   
 
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
DATA;
$x = preg_replace('/(\d+)\s+(\d+)\s+(\d+)/','
<br><font color="#FF00FF">$1</font>
<font color="#00FF00">$2</font>
<font color="#0000FF">$3</font>
',$data);
echo $x;
?>

Open in new window

0
CFILAuthor Commented:
Perfect
0
dr_dedoCommented:
well, when i asked you earlier about patterns to follow, i wanted to know what to code.
now, you want to skip certain lines ?? is that what u need ? please proved a and example
0
CFILAuthor Commented:
Hi ,
i mean some time i have a text which is has number in the line then text then number like
$data = <<<DATA
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
 
1             2              3
3              5             4
8          4                                        10
8          4                                        10
8          4                                        10  
 
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
i don't have exact text , because 1 got lots of text files ,, maybe all files same as this
8          4                                        10
8          4                                        10  

DATA;

your previous code was what i want , but now i want to do some develop of it so i can used the function with other files if i understand the idea if how can i choose certain number line of the text comes between it ..

thank you ,  and sorry for the lots of question ..
CFIL
0
dr_dedoCommented:
it would be very difficult to allow only some lines and ignore others
you may break up your data into line
$newData = explode ("\n",$data) and specify which lines to use, but other ways are next to impossible
0
CFILAuthor Commented:
hi ,.,

good idea about that $newData = explode ("\n",$data)
but how can i specify the line ? maybe i would like choose the line number 10 to 13 .. after do that
$newData = explode ("\n",$data)

0
dr_dedoCommented:
try this


$dataArr = explode ("\n",$data);
$startLine = 10;
$endLine=13;
for ($i=$startLine-1; $i<$endLine ; $i++){
$dataArr[$i] = preg_replace('/(\d+)\s+(\d+)\s+(\d+)/','
<br><span class="style1_1">$1</span>
<span class="style1_2">$2</span>
<span class="style1_3">$3</span>
',$dataArr[$i]);
}
$data = implode  ( "\n"  , $dataArr  );
echo $data

Open in new window

0
CFILAuthor Commented:
nice ,, i don't know what can i say ,, perfect it works fine ..

thank you very much sir for helping me ..

CFIL
0
dr_dedoCommented:
glad i could help you :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.