colorize/line a specific word

hello guys, first of all thank’s to everyone whoever takes time to answer or even read this thread.
(I’m sorry i’ve you have a hard time understanding whatever i’m trying to explain)

basicly i’ve created a php file, who is getting the information from my ftp on the forums.
but it’s extremely messy since it had no breaks just continues the lines after lines.

my question to you guys is is there a way to colorize a specific word such as “hey?” or “welcome.”
the thing is it’s not the same line it changes every few seconds. so i can’t just go in the logs can’t colorize that word since it’s changing eachtime.

i need a code such as "if line contains “hey” <colorize it in red.
example:
[11:55:39] ------------------Round: 0--------------------[11:56:31] Hey shot welcome for 7 damage with a gun.

and second question is how can i numberize the lines without creating a table?
[11:55:39] ------------------Round: 0--------------------
[11:56:31] Hey shot welcome for 7 damage with a gun.

^ that’s how i want it to show on the forums.
thank you for reading, and trying to help me! if i explained it wrong i would be grateful if you correct me!

Please add an example of your input data (multiple lines), and how you want that to display.

Also, how do you get the input data (you could add the code). Do you read a log file (x last lines), or something else?

[code]

<?php $ftp_ip="-"; $ftp_user="-"; $ftp_pass="-"; $ftp_log_path="my/log/path/blabla.log"; $temporary_file="test.tmp"; //Login with username and password $conn_id = ftp_connect($ftp_ip); $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass); ftp_pasv($conn_id, true); // get the file $local = fopen($temporary_file, "w"); // try to download $ftp_log_path and save it to $temporary_file //if (ftp_fget($conn_id, $local, $ftp_log_path, FTP_ASCII, 0)) { //}// $result = ftp_fget($conn_id, $local, $ftp_log_path, FTP_ASCII); // close the FTP stream //ftp_close($conn_id); // close the connection and the file handler $myFile = $temporary_file; $fh = fopen($myFile, "r"); $theData = fread($fh, filesize($myFile)); fclose($fh); echo $theData; ?> [/code]

basicly, it’s getting the blabla.log from a other ftp and pastes whatever codes in that file to the test.tmp
and whatever is in the test.tmp it echo’s it on the .php
it’s about the logs of the server

there are 3 tags, let’s say [hey] [hello] [hia]

Examples: [14:34:05] ------------------Round: 1-------------------- [14:34:07] [hey] guy shot [hello] guy for 10 damage[14:34:08] [hello] guy shot [hia] guy for 5 damage[14:34:09] [hello] guy shot [hey] guy for 41 damage
etc etc

that’s how it shows up on the mywebsite.com/test.php

i want to colorize the 3 tags, and line them up like this:
[14:34:05] ------------------Round: 1--------------------
[14:34:07] [hey] guy shot [hello] guy for 10 damage
[14:34:08] [hello] guy shot [hia] guy for 5 damage
[14:34:09] [hello] guy shot [hey] guy for 41 damage

so it isn’t confusing.

[member=71845]JimL[/member] sorry for the double post but if you want me to explain more like whatever you wanna know please tell me and thanks for helping!

Ok, I would split it in two parts

task 1 - split the log into n lines
here you could do a regular expression to select each timestamp + text and then output them with line breaks

task 2 - highlight words
create a function (or multiple) to hightlight words in a given text, you can find some examples here:

[member=71845]JimL[/member] thank you for the hard work but, i still don’t get it i’m a noob :confused: could you paste me the code? for the examples that are shown up ?

If you explain what you don’t get it would be easier to help. A code pasting service won’t help you understand much.

well that code didnt work for me :confused:

that’s for bold i need for color :frowning:

like i said on the thread, the code you see up get’s the logs of whatever happend in the server on the tmp and the tmp outputs the logs on the .php so what i wanna know is how i can colorize a few words that are shown on the php( it’s all automaticly)

example:
$myString = “hey”;
$formattedString = blue(‘hey’,$myString);
echo $formattedString ;

it will echo hey

but only if the tmp file contains

hey
it must echo it otherwise not [member=71845]JimL[/member]

thanks once again for the help !

just change it from bold to another tag, ie

[member=71845]JimL[/member]

[php]$myString = ‘hey’;
echo $myString;[/php]

this is the code what i used like you said but the problem is it’s echoing a new word “hey”
but i don’t want that, i want it echo all the words that contains hey inside the php

once again i really appreciate all your hard work and help!

seems like you looked at the question, have a look at this answer

[member=71845]JimL[/member] i really, Really don’t understand it…

What in the linked answer is it you’re having trouble with?

I’m not trying to be a pain here, I just believe in that “give a man a fish vs teach a man to fish” thing.

You can also try to implement these things in a way you are comfortable with. You could explode by space to get an array with individual words. Then loop through the words, replacing the words you are after with what you want, and then imploding the array into a normal string again.

That’s the beauty of programming, there are always a multitude of solutions to problems. And by solving problems you can only get better :slight_smile:

id rather just to have the fish right now :confused: been 3 days i’m kinda about to give up if i can’t find it today…
[member=71845]JimL[/member]

I think there are some regulars here who do coding work, try posting in the freelancing forum

Pretty sure [member=46186]Kevin Rubio[/member] is available for hire.

Sponsor our Newsletter | Privacy Policy | Terms of Service