I'm returning some data as an array from a mySQL table using PHP, and need to replace some values with empty strings.
I'm wondering if it's possible for me to use a regular expression to match everything except the contents of a variable, the variable contains an email addresses (if that makes any odds) and the email address (can) appear in each array value.
As an example, I would want everything except "email@email.com" to be matched, so that I could replace all other instances in the array with an empty string, but not "email@email.com".
I've achieved the outcome I want using a string value, and a function that replaces 'valueA' with 'valueB' but not using a variable so far.
Example of the while loop that is returning the rows of data from the SQL query, and the static string variable that i've used to test the search and replace.
while($row = $result->fetch_assoc()) {
$replace = "email@email.com";
print_r(str_replace($replace,"",$row,$i));
echo "Replacements: $i";
I did wonder if this is possible with an SQL query (i.e filtering to column values that contain the variable that i'm interested in) - but I couldn't find a way to do that without writing lots of and statements.
This is my current SQL query:
$sql = ("SELECT * FROM calendar WHERE `8am` = '$currentUser' OR `9am` = '$currentUser' OR `10am` = '$currentUser'")
Thanks