How to seperate imdb id from the imdb movie link [duplicate] - php

This question already has answers here:
get file name for url php
(2 answers)
Closed 3 years ago.
I want to separate IMDb id from the link
my php code is this
<?php print $movie_info[0]->imdb_link; ?>
the URL seems like this on every page .
https://imdb.com/title/tt1206885
i want to show this id separate from the url on my page => tt1206885
please help me
i try but fail to extract the id
<?php if($movie_info[0]->imdb_link){?>
ID <?php $str = explode("/",$movie_info[0]->imdb_link);
/* if url in php variable then $str = explode("/",$imdb_id); */
print $str[count($str)-2];
?>">
<?php }?>

$link_array = explode('/', $movie_info[0]->imdb_link);
$id = end($link_array);

Related

How do I remove the query string in PHP? [duplicate]

This question already has answers here:
How to remove the querystring and get only the URL?
(16 answers)
Closed 2 months ago.
My goal: compare the actual url to a stored url in MySQL DB. If there's a match the page title and meta description info is loaded from the DB into the fields on the page.
Problem: I need to remove the query string so the url is clean for the comparison.
The existing code works for the main pages that list the blogs/lessons/etc, but when I go to page 2, 3, 4, etc the query string breaks the comparison.
In the code you will see $actual_link - that needs to have the query string removed and that is what I have yet to find a solution that actually works, as for what I've tried, there have been too many iterations to remember them.
Server Info: PHP 7.3.17; MySQL MariaDB-10.2.32; Apache-2.4.43/
$actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$sql = "SELECT * FROM meta WHERE siteLink = '$actual_link'";
$result = mysqli_query($link, $sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
?>
<?php include_once "myHead.php"; ?>
<title><?php echo $row["title"]; ?></title>
<meta name="description" content="<?php echo $row["meta_desc_content"]; ?>">
<?php
}
}
else
{
echo "Shit, it ain't working.";
}
?>
PHP provides a nice helper method called parse_url to get certain parts of an url:
// $actual_link = 'www.stackoverflow.com/test';
$urlParts = parse_url($actual_link);
$formattedUrl = $urlParts['host']; // www.stackoverflow.com
Docs: https://www.php.net/manual/en/function.parse-url.php
Use strtok()
like this: $baseUrl = strtok($actual_link, '?');

Put php value in the end of a link [duplicate]

This question already has answers here:
How to echo inside html tags
(6 answers)
Closed 5 years ago.
Script 1.
add_action('asgarosforum_after_post_author', 'my_function_asgaros_cabinet', 10, 1);
function my_function_asgaros_cabinet($author_id) {
$userData = get_userdata($author_id);
if (!empty($userData) && !empty($userData->description)) {
echo $userData->description;
}
}
Script 2.
I want to put this in script 1 and put ''description'' in the end of that link.
How to do that and whats the right way/code? Cause i think my code is wrong.
<iframe src="http://test.com/me.php?sid='echo $userData->description'"></iframe>
Try with adding the php tag:
<iframe src="http://test.com/me.php?sid=<?php echo $userData->description?>"></iframe>
or
You can try to write the all iframe tag with php:
echo '<iframe src="http://test.com/me.php?sid='. $userData->description .'"></iframe>'

Get URL of the video ID [duplicate]

This question already has answers here:
Get id of a particular URL the post [duplicate]
(2 answers)
Closed 6 years ago.
Get URL of the video ID
I need to get any ID in the URL http://www.blogger.com/video-play.mp4?contentId=7c6255ca14e901d2
each post there is video with different url
video-play.mp4?contentId="XXXXXXXXX"
Store the ID in a variable for later use
Able to develop code below but I can not get any id in the video-play.mp4?contentId="XXXXXXXXX"
$video_string = '[videojs mp4="http://www.blogger.com/video-play.mp4?contentId=7c6255ca14e901d2" poster="https://2.bp.blogspot.com/-lSTjYuDBiAQ/VvST8Z7z2OI/AAAAAAAAGPY/c8yAE675bLEMYI-OMwtauCiXeu1yZPZaw/s1600/fundososvideos.jpg" preload="none" controls="controls" width="100%" height="400"]';
if (preg_match('/mp4="(.*)"\sposter/', $video_string, $matches1)) {
$url = $matches1[1];
$id = explode('=',parse_url($url)['query'])[1];
<?php echo 'DOWNLOAD'; ?>
}
You Url http://www.blogger.com/video-play.mp4?contentId=7c6255ca14e901d2
If contentId is same then you can try with this
if(isset($_GET['contentId'])){
echo $id = $_GET['contentId'];
}
If the url is no POSTed you can use parse_url on the video url that return an associative array.
Then use parse_str that parse the string into variables
$url = 'http://www.blogger.com/video-play.mp4?contentId=7c6255ca14e901d2';
$parsed_url = parse_url($url);
parse_str($parsed_url['query'], $parsed_str);
if(isset($parsed_str['contentId']))
{
echo $parsed_str['contentId'];
}

PHP add another get method to url after submiting [duplicate]

This question already has answers here:
How to add url parameter to the current url?
(7 answers)
Closed 7 years ago.
I have an search method who redirect to something like this:
mysite.ro/search.php?a=1&b=2&c=3
When i have pagination i need to redirect me to something like this:
mysite.ro/search.php?a=1&b=2&c=3&page=2
I dont know the solution to have an href who redirect to page=2 and keep the same search criteria.
I tried <a href="&page=2"> and href="<?php echo $_SERVER[REQUEST_URI];?>&page=1" not usefull both.
Try this, Its worked for me.
<?php
$actual_link = '';
$delimiter = '?&page=';
$link = array();
$actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$links = explode($delimiter, $actual_link);
?>
<a href="<?php echo $links[0];?>?&page=1" >Link </a>

Get the path with query string on the current http request in PHP [duplicate]

This question already has answers here:
Get the full URL in PHP
(27 answers)
Closed 3 years ago.
I need to get the path with query string from the URL of the current request. For example, if the current URL is:
"http://www.example.com/example/test/hi.php?randomvariable=1"
I would want this:
"/example/test/hi.php?randomvariable=1"
You want $_SERVER['REQUEST_URI']. From the docs:
'REQUEST_URI'
The URI which was given in order to access this page; for instance, '/index.html'.
it should be :
$_SERVER['REQUEST_URI'];
Take a look at : Get the full URL in PHP
<?php
function current_url()
{
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$validURL = str_replace("&", "&", $url);
return $validURL;
}
//echo "page URL is : ".current_url();
$offer_url = current_url();
?>
<?php
if ($offer_url == "checking url name") {
?> <p> hi this is manip5595 </p>
<?php
}
?>

Categories