Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.