Andre
Andre

Reputation: 638

How to check if string contains another string - laravel

I'am working with URLs and I'm try to checkif an url has the words I am looking for

I'm using this

$alreadySaved = 'storage.googleapis';
   $contains = Str::contains($alreadySaved, $imageUrl);

   if ($contains == false) {

but the result of $contains is false EVER

for example

enter image description here

that $imageUrl has storage.googleapis word

how can I solve it?

I need to obtain if the string has "storage.googleapis" and return true

Upvotes: 0

Views: 3281

Answers (1)

Joshua Baldwin
Joshua Baldwin

Reputation: 106

It looks like all you need to do is switch $alreadySaved and $imageUrl. Laravel's Str::contains method takes the string you're searching through first and the substring second.

Like this:

$contains = Str::contains($imageUrl, $alreadySaved);

Upvotes: 4

Related Questions