I’m writing a function that takes in a string ($skill), and a list of allowed characters in a regex.
Here is the requirements on the homework
- Skill-name: required; can’t be too long; can contain spaces, hyphens, apostrophes (and of course alphanumeric characters), but no other characters
- As part of this step, you must have a php function that takes in a string and a list of allowed characters (or, dis-allowed characters, or perhaps even a regular expression), and returns a an error message (if the string doesn’t match the requirement), or the empty string (if the string does match the requirement). Be sure to give a descriptive name to this function.
This is the code I have
function validate_skill($skill, $list) {
if (preg_match('/['.$list.']/',$skill)) {
echo "The skill contains a match.<br />";
}else{
echo "The skill does not contain a match.";
}
}
I’m only receiving a blank page, and through commenting out the function, the page then works. Is this the proper way to have a variable be inside an expression?
You’ve either misunderstood your requirements, or you’re approaching this wrong. Here’s the simplified version of the requirements:
You should be working on those points.
Also, on a different note, you have a syntax error.
echo echo, should probably beelse echo.