Ratibor  Yaroslavovich
Ratibor Yaroslavovich

Reputation: 82

PHP code if part of url contains *this* then do *this*

I have a joomla site. I have an index.php that contains PHP code that displays divs + HTML code with divs

I have another index.php that should go on with /en and /fr versions. and I have another version of index.php that I described above. I need to display one index.html on /ru version and another one on /en+/fr versions.

In other words, I need to echo some code in mysite.com/ru and another code on mysite.com/en + mysite.com/fr

<?php
$url = "http://mysite/en/";
$currentpage = $_SERVER['REQUEST_URI'];
if($url==$currentpage) {
echo 'index.html version one'
?>

But this didn't work.

Upvotes: 2

Views: 855

Answers (2)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72299

Use strpos():-

if(strpos($url ,'en/') !== FALSE || strpos($url ,'fr/') !== FALSE) {
echo 'index.html version one';
}
if(strpos($url ,'ru/') !== FALSE){
echo 'index.html version two';
}

Example link:- https://eval.in/734505

Reference:-http://php.net/manual/en/function.strpos.php

Upvotes: 5

Ratibor  Yaroslavovich
Ratibor Yaroslavovich

Reputation: 82

Thank you again. Here is my solution:-

<?php 
$url = $_SERVER['REQUEST_URI']; 
if(strpos($url ,'en/') !== FALSE || strpos($url ,'fr/') !== FALSE) { ?> 
<div>my code for en+fr</div> 
<?php } else { ?> 
<div>my code for ru</div> 
<?php } ?>

Upvotes: 1

Related Questions