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 7622085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:21:49+00:00 2026-05-31T04:21:49+00:00

I have a string $eventdays which holds information regarding which days are selected. The

  • 0

I have a string $eventdays which holds information regarding which days are selected.

The format of the data is:

Monday = Mo 
Tuesday = Tu
Wedneday = We
Thursday = Th
Friday = Fr
Saturday = Sa
Sunday = Su

Mo,Tu,We,Th,Fr,Sa,Su

So if for example Tuesday and Friday were selected, the string would be:

Tu,Fr

If Monday, Wednesday, and Saturday were selected it would be:

Mo,We,Sa

Note: Any combination of days can be selected.

I was wondering how to get this information, and preselect checkboxes. The checkboxes are:

<input type="checkbox" name="days[]" value="Mo" />Monday<br />
<input type="checkbox" name="days[]" value="Tu" />Tuesday<br />
<input type="checkbox" name="days[]" value="We" />Wednesday<br />
<input type="checkbox" name="days[]" value="Th" />Thursday<br />
<input type="checkbox" name="days[]" value="Fr" />Friday<br />
<input type="checkbox" name="days[]" value="Sa" />Saturday<br />
<input type="checkbox" name="days[]" value="Su" />Sunday<br />

I know how to preselect a checkbox (checked = “yes”), but my question is how can I parse the string and then select the correct checkboxes from that information?

  • 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-31T04:21:50+00:00Added an answer on May 31, 2026 at 4:21 am

    You can use strpos and dynamically generate your checkboxes.

    $eventdays = "Tu,Fr"; // Selected days
    
    $days = array( "Monday"   => "Mo",
                   "Tuesday"  => "Tu",
                   "Wedneday" => "We",
                   "Thursday" => "Th",
                   "Friday"   => "Fr",
                   "Saturday" => "Sa",
                   "Sunday"   => "Su"
                );
    
    foreach ($days AS $day => $shortDay) {
        // Is there an event on this day?
        $checked = strpos($eventdays, $shortDay) !== FALSE ? "checked='checked'" : "";
        // Generate checkbox HTML
        echo "<input type='checkbox' name='days[]' value='{$shortDay}' {$checked} />{$day}<br />"; 
    }
    

    Output

    <input type='checkbox' name='days[]' value='Mo' />Monday<br />
    <input type='checkbox' name='days[]' value='Tu'  checked='checked'/>Tuesday<br />
    <input type='checkbox' name='days[]' value='We' />Wedneday<br />
    <input type='checkbox' name='days[]' value='Th' />Thursday<br />
    <input type='checkbox' name='days[]' value='Fr'  checked='checked'/>Friday<br />
    <input type='checkbox' name='days[]' value='Sa' />Saturday<br />
    <input type='checkbox' name='days[]' value='Su' />Sunday<br />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string which is of format: ;1=2011-10-23T16:16:53+0530;2=2011-10-23T16:16:53+0530;3=2011-10-23T16:16:53+0530;4=2011-10-23T16:16:53+0530; I have written following code to
I have string in which it has Date of type- 'mm-dd-yyyy'; I have to
I have String in the following format blah blah [user:1] ho ho [user:2] he
I have string which contains every word separated by comma. I want to split
I have string which contains something about amount 3 val 6, amount 7 val
I have string data and height is changable, it can be like this: John
I have string with product information and I would like to parse that string
I have string like 123-123-1234 so I want to convert string into this format
I have string in following format some other string @[Foo Foo](contact:2) some other string
I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to

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.