Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Wrapping Up The Project Validating Contact Form Data

Nino Roldan
PLUS
Nino Roldan
Courses Plus Student 9,308 Points

placing stripos in a function

in the effort of making the code more "compact" (i.e. putting functions that are going to be accessed by multiple pages into an inc folder), i was thinking of putting the stripos function inside a helper file.

the actual code works if i just paste it on the webpage but when i try to put it on a function named "nrstripos()", i get an error.

this is the actual stripos function - this works.

    foreach ($_POST as $value) {
        if (stripos($value, 'Content-Type:') !== FALSE) {
            echo "There was a problem with the information you entered.";
            exit;
            }
    }

this is the function that i placed on a helper file inside an inc folder - this doesn't work

 function nrstripos($postfrompage)  {
                foreach ($postfrompage as $value) {
                    if (stripos($value, 'Content-Type:') !== FALSE) {
                        echo "There was a problem with the information you entered.";
                        exit;
                        }
                      }
                }

and i call it from the page through this where I pass the $_POST variables into the nrstripos function.

 nrstripos($_POST);

1 Answer

Nino Roldan
PLUS
Nino Roldan
Courses Plus Student 9,308 Points

Say this in Homer voice : " D'oh!"

I wrote the function on a file that is houses in a different inc folder! Now I have rectified this, placed the function in a file inside the correct inc folder and the function is working now, ready to be accessed from within by all of the pages! Thanks!