3

How can I check data using something like strpos

data->url = www.youtube.come/12345

@if($data->url != 'youtube' )

@endif

updated  how can i put this in my balde temp

preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+|(?<=/videos/)[^&^/\n]+#", $line['YOUTUBE'], $matches);

        $videoId = $matches[0];

        if(substr_count($line['YOUTUBE'], "facebook.com") > 0){
          print "<div class=\"fb-video\" data-href=\"{$line['YOUTUBE']}\" data-allowfullscreen=\"true\" data-width=\"600\"></div>";
        }else{
          print "<iframe width=\"600\" height=\"350\" frameborder=\"0\" src=\"https://www.youtube.com/embed/{$videoId}?autoplay=1\"></iframe>";
        }
1
  • Have you tried using strpos @if(strpos($data->url, 'youtube') ===false) Commented Oct 31, 2017 at 7:33

2 Answers 2

4

You can use strpos(), strstr() (or their case insensitive variants when appropriate) but also you can use Laravel's str_contains() function which is basically using strpos() PHP inbuilt method:

$contains = str_contains($line['YOUTUBE'], "facebook.com");
Sign up to request clarification or add additional context in comments.

Comments

3

You can use any php function within blade too... see example below:

 @if (strpos($data->url, 'youtube') !== false) {
   echo 'true';
 @endif

Update: In some situations, it's useful to embed PHP code into your views. You can use the Blade @php directive to execute a block of plain PHP within your template:

@php
//
@endphp

While Blade provides this feature, using it frequently may be a signal that you have too much logic embedded within your template. Reference: https://laravel.com/docs/5.4/blade#php Hope it will help you. :)

3 Comments

thnk you sirrrr
So is my answer :)
And please don't call me (or anyone) sir.. its weird :D Everyone here is learning, some are new and some are old, this is the only difference.

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.