Compare URL to PHP

Asked

Viewed 383 times

0

I want to make a if to compare Urls, I tried using parse_url... but I’m not sure how to use it. Someone could help me out a little?

<?php 
    $url1 = parse_url ( "http://enquetegoias.esy.es" ); 
    $url2 = parse_url ( "http://enquetegoias.esy.es/pesquisa.html" );
?>
<?php if ($url1['host']  == $url2['host'] ): ?>

        <meta property="og:image" content="http://enquetegoias.esy.es/img/logo.jpg" />

        <meta itemprop="image" content="http://enquetegoias.esy.es/img/logo.jpg" />

    <?php else: ?>

        <meta property="og:image" content="http://enquetegoias.esy.es/img/votacao.jpg" />

        <meta itemprop="image" content="<?=URL?>img/layout/votacao.jpg" />

    <?php endif ?>
  • You want to compare to get that result ?

  • If url1 equals http://enquetegoias.esy.es{ <meta Property="og:image" content="http://enquetegoias.esy.es/img/logo.jpg" /> <meta itemprop="image" content="http://enquetegoias.esy.es/img/logo.jpg" />} else{ <meta Property="og:image" content="http://enquetegoias.esy.es/img/votacao.jpg" /> <meta itemprop="image" content="<?= URL? >img/layout/voting.jpg" />}

  • Try to clarify your question a little more. What is the expected result? The check is correct.

  • For example, if the user’s page is http://enquetegoias.esy.es then I want it to appear: <meta Property="og:image" content="http://enquetegoias.esy.es/img/logo.jpg" /> <meta itemprop="image" content="http://enquetegoias.esy.es/img/logo.jpg" /> but if the usurer is in http://enquetegoias.esy.es/pesquisa.html I want it to appear: <meta Property="og:image" content="http://enquetegoias.esy.es/img/votaca.jpg" /> <meta itemprop="image" content="<?= URL? >img/layout/voting.jpg" />

  • Can you do it? @Fernandaferreira

  • I couldn’t, I couldn’t

  • managed to develop?

  • Not yet (I stopped stirring). You’re having the same difficulty?

Show 3 more comments

1 answer

1

strcmp( string $str1, string $str2 )

Takes two strings as parameter. Returns < 0 if $str1 is less than $str. Returns > 0 if $str1 is greater than $str2 and finally returns 0 if the two strings are equal.

strcasecmp( string $str1, string $str2 )

Identical to strcmp(), with the difference that strcmp() is case-sensitive, and strcasecmp() is case-insensitive.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.