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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:26:27+00:00 2026-06-07T15:26:27+00:00

I’m a newbie in PHP and I’m confused about GET method. Why the $text

  • 0

I’m a newbie in PHP and I’m confused about GET method.

Why the $text in the condition of the loop works with Appserv in Windows 7, but when I tried this code with Xampps on Mac it won’t work I’ve to use for($i=0; $i<strlen($_GET['text']); $i++) instead.

At first, I understand that after I used isset($_GET['text']) so next time I just use only $text, but now I’m confused.

<? $color = array("#FFCCFF", "#FFCCCC", "#FFCC99", "#FF99FF", "#FF99CC",
    "#FF9999", "#FF66FF", "#FF66CC", "#FF6699", "#FF6666");
if (isset($_GET['text'])) { 
    for($i=0; $i<strlen($text); $i++) { 
        $j = $i%10 ?>
        <font color=<?= $color[$j]?>><? echo "$text[$i]"; ?></font>
    } 
} else {
    echo "Empty String";
} ?>

The problem is solved by many of your help.

<?php $color = array("#FFCCFF", "#FFCCCC", "#FFCC99", "#FF99FF", "#FF99CC",
    "#FF9999", "#FF66FF", "#FF66CC", "#FF6699", "#FF6666"); 
if( isset($_GET['text'])) {
    $text = $_GET['text'];
    for( $i=0; $i<strlen($text); $i++) {
        $j = $i%10;
        echo "<font color=$color[$j]>$text[$i]</font>";
    }
} else
    echo "Empty string";
?>

btw I’m trying to use HTML + PHP only because I want to practice with HTML before go in deep with CSS.

  • 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-06-07T15:26:29+00:00Added an answer on June 7, 2026 at 3:26 pm

    The actual answer to your question, if $text is working as an alias for $_GET['text'] is probably that your Windows server is configured with register_globals set to on, which would mean that anything passed over in your query string would be turned into the appropriate variable.

    ie. ?awesome=true == $awesome = 'true'

    This is bad. Disable register_globals at the offending side, and use $_GET['text'] to access your data.

    Your code would look better a little something like this:

    <?php
    $color = array("#FFCCFF", "#FFCCCC", "#FFCC99", "#FF99FF", "#FF99CC",
                    "#FF9999", "#FF66FF", "#FF66CC", "#FF6699", "#FF6666");
    if (isset($_GET['text'])) {
        $text = $_GET['text'];
        for($i=0; $i < strlen($text); $i++) { 
            $j = $i % 10; ?>
            <span style="color: <?= $color[$j] ?>"><?= htmlentities($text[$i]); ?></span>
        <?php } 
    } else {
        echo "Empty String";
    }
    ?>
    

    Note that I have tidied up your code and made it slightly more sane/safe. htmlentities is used to stop XSS vulns that could come from this, despite being unlikely due to splitting the string. You were mixing up <?php echo .. ?> and <?= .. ?> for some reason, despite them being the exact same thing. Also, don’t use <font>.

    You said this:

    At first, I understand that “after I used isset($_GET[‘text’]) so next time I just use only($text), but now I’m confused.

    If you know you’re mixing them, why are you doing it? If you’re checking for $_GET['text'] being set, then it’s only logical that you would use that for access also.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.