Jump to content

styling a .txt file?


foevah

Recommended Posts

Hi everyone,

 

I would like to know how to output a .txt into a PHP page and then style the text that is inside the .txt file.

 

For example lets say I have this in the .txt file:

 

Hello my name is Mattew

 

Then on my PHP page I would like the .txt file to be shown with styles like this:

 

Hello my name is Mathew

 

Please can someone help me? I have done some research but I have not had much luck in finding an exact solution.

 

Link to comment
https://forums.phpfreaks.com/topic/108719-styling-a-txt-file/
Share on other sites

If you for example want all instances of "Mathew" to be in red, str_replace (or str_ireplace, for case insensitivity) will suffice:

 

<?php
$text = file_get_contents('path/to/filename.txt');
// $text now holds 'Hello my name is Mathew'
$text = str_replace('Mathew', '<span style="color: red;">Mathew</span>', $text);
echo $text;
// Hello my name is <span style="color: red;">Mathew</span>
?>

Link to comment
https://forums.phpfreaks.com/topic/108719-styling-a-txt-file/#findComment-557672
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.