Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3215018
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:07:43+00:00 2026-05-17T15:07:43+00:00

I have data in a notepad file as following: A 1-6 A 1-7 B

  • 0

I have data in a notepad file as following:

A   1-6
A   1-7
B   1-8
B   1-9
B   1-10
c   1-11
C   1-12
D   1-13
F   1-14
F   1-15
f   1-16

I want above data to be updated as below in the notepad file:

<strong>A</strong>  1-6
A   1-7
<strong>B</strong>  1-8
B   1-9
B   1-10
<strong>c</strong>  1-11
C   1-12
<strong>D</strong>  1-13
<strong>F</strong>  1-14
F   1-15
f   1-16

Which means adding a <strong> tag or any other tag with first character alphabetically. The data in file is sorted alphabetically (A to Z).

I want to achieve this in PHP using RegEx techniques, please help!

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:07:44+00:00Added an answer on May 17, 2026 at 3:07 pm

    I’d do something like :

    $seen = array();
    $file = array(
    'A   1-6',
    'A   1-7',
    'B   1-8',
    'B   1-9',
    'B   1-10',
    'c   1-11',
    'C   1-12',
    'D   1-13',
    'F   1-14',
    'F   1-15',
    'f   1-16'
    );
    foreach($file as $line) {
        $L = strtoupper(substr($line, 0, 1));
        if (!isset($seen[$L])) {
            $line = preg_replace('!^(.)!', "<strong>$1</strong>", $line);
            $seen[$L] = 1;
        }
        echo $line,"\n";
    }
    

    Output:

    <strong>A</strong>   1-6
    A   1-7
    <strong>B</strong>   1-8
    B   1-9
    B   1-10
    <strong>c</strong>   1-11
    C   1-12
    <strong>D</strong>   1-13
    <strong>F</strong>   1-14
    F   1-15
    f   1-16
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file 4 bytes long called data.txt with following content (four 8
In Notepad you can Open any File and it will display the raw data
I have two notepads and each notepad contains some data. Let's say Notepad 1
I have data stored as below in an MS Access database: Date User 20090101
I have data of program usage in excel file, the data has date and
I have data in an SQL Server 2005 database which I need to copy
I have data for countries which include Name, Population, Area etc for countries... What
I have a text file in my computer which i am reading form my
I have a text file in my computer which I am reading form my
I currently have a sproc that is exporting data to a csv file using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.