0

Trying to figure out what I am dong wrong here but I am trying to search row 6 and replace the phrase "Plenty of stock available!" (with the quotation marks as it is in a CSV) with the number "10".

It works no issues when then with the 'lowstock' text, but not the "Plenty of stock available!". I have added the \ before it as to have it ignore the quotation mark (and view it as text).

 //changes stock status
    $row = fgetcsv($file);
    if (strtolower($row[6]) == '\"Plenty of stock available!\"' || strtolower($row[6]) == 'lowstock') {
    $row[6] = '10';
    } else if (strtolower($row[6]) == 'nostock') {
    $row[6] = '2';
3
  • 3
    strtolower($row[6]) will never match a P, did you mean p instead? Commented Nov 8, 2017 at 4:58
  • strtolower($row[6]) == '\"Plenty of stock available!\"' need to be strtolower($row[6]) == strtolower('"Plenty of stock available!"') Commented Nov 8, 2017 at 5:04
  • I don't get why you wouldn't just use a lower case 'p' in the string. Commented Nov 8, 2017 at 5:08

1 Answer 1

1

I would try the following:

$row = fgetcsv($file);
// Don't modify the original data (unless you need to) and 
// remove duplicate calls to strtolower()
$r6 = strtolower($row[6]);
// Only test against lower case letters, " should not be needed
if ($r6 == 'plenty of stock available!' || $r6 == 'lowstock') {
    // perform correction / change
    $row[6] = '10';
} else if ($r6 == 'nostock') {
    // perform correction / change
    $row[6] = '2';
}
Sign up to request clarification or add additional context in comments.

2 Comments

@LukeAppel if that's the case, then your row[6] value never contained quote characters
@LukeAppel - Cool, glad to have helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.