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

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>'

Related

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

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);

PHP Add if statement html variable [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 4 years ago.
I am trying to add if statemenet into $html variable. But it see php as a html tag. how can add this statement. Thanks
$html = '
<?php if (x=y):?>
<div>
Help me )
</div>
<?php endif ?>
';
Try following
$html = '';
if(x==y):
$html .= '<div> Help me )</div>';
endif;
You can do without closing php tags.
Edited
After #MichaƂSkrzypek comment I have edited and fix mistake in if statement
What you are trying to do is impossible. If you would want to echo the var, you would put <?php inside of <?php, which must result in an error. Only add
<div>
Help me )
</div>
to a var.

PHP loop is not throwing the correct link [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
for my issue i'll try to be as brief as possible
what am trying to do is reference a page with a specific id in the HTML anchor link with PHP as the below
<body>
<?php $linkName = "Second Page"; ?>
<?php $id = 5; ?>
<?php echo $linkName?><br>
and it works fine
now what am trying to do is to make the $id part more dynamic by making looping the number from 1 to 10 and also providing 10 links
the code is
</head>
<body>
<?php $linkName = "Second Page"; ?>
<?php $id = 5; ?>
<?php
for ($i=0; $i < 10 ; $i++) {
echo "<a href='secondPage.php?id=<?php echo $i;?'>Link1</a>";
};
?>
</body>
however what i did notice as the below images indicates when i hover on the links i noticed that i refer to a strange link
and when i cliched on it it takes me to the following link with an id that i did not want as below
http://localhost/PHP_Course/secondPage.php?id=%3C?php%20echo%201;?
i tried researching the subject and i tried escaping the quotation but it does not seem to resolve the problem
Any help please ??
<?php and ?> tags indicate to the PHP preprocessor that anything inside them is code and needs to be parsed, everything outside is just text PHP doesn't touch.
Inside the <?php tag, "<?php" string has no special meaning, so is printed. You do not need to open and close tags all the time, try this:
</head>
<body>
<?php
$linkName = "Second Page";
$id = 5;
for ($i = 0; $i < 10 ; $i++) {
echo "<a href='secondPage.php?id=$i;'>Link1</a>";
};
?>
</body>
You're echoing a string in PHP, and using <?php... inside that string.
Solution:
echo "<a href='secondPage.php?id=" . $i . "'>Link1</a>";
id=$i will also work, because you can include variables directly in double-quoted strings.
You're echoing the PHP code itself as a string. You don't need to put PHP code inside of PHP code. Just concatenate the values you want to echo:
echo 'Link1';
because you already started an echo statement so you don't need to add another PHP starting and ending tags. just check my code below and try it.
<?php
for ($i=0; $i < 10 ; $i++) {
echo "<a href='secondPage.php?id=".$i."'>Link1</a>";
} ;
?>

Write the text that is between h1 tags [duplicate]

This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
Closed 8 years ago.
How can we take in PHP or jQuery that is written between the <h2> </h2> of each page to put the title of my pages so that each page is different.
Example:
<section class="sub_header">
<h2>Contact</h2>
<h5>Contactez-nous !</h5>
</section>
=> <title>Contact</title>
It's possible ?
PHP, jQuery load() function...?
Thanks
My soluce:
I answer because it could be used for some.
I'll add this little code on important pages. using the superglobal 'REQUEST_URI':
<?php
if ($_SERVER['REQUEST_URI'] == '/index_contact.html') {
$data = 'Contact';
}elseif(
$_SERVER['REQUEST_URI'] == '/index_blog.html') {
$data = 'The blog';
}else{
$data = 'Default title.';
}
// Display the name of the page if data exists
if (isset($data)) {echo $data;} ?>
Hoping that it will be useful for some.
You can try with prag_match to extract data between h1 tag.
$data ="Your content goes here";
preg_match('/<h2>(.*?)<\/h2>/s', $data, $matches);
echo $matches[1];
exit;

Get All Strings between tags and echo them? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Get content between two strings PHP
Ok, here is my delima:
here is an example of my $content :
<!--nextpage-->First Title Here<!--nexttitle-->
some more text here
and here and here and here
a little more here!
<!--nextpage-->Second Title Here<!--nexttitle-->
some more text here
and here and here and here
a little more here!
<!--nextpage-->Third Title Here<!--nexttitle-->
some more text here
and here and here and here
a little more here!
How could I run a function that finds all "get_all_strings_between()" and echo them at the top of the $content:
**First Title Here** / **Second Title Here** / **Third Title Here**
and then my content HERE!
THanks!!
If I understood your question correctly this regexp will do it:
function get_all_strings_between($content) {
preg_match_all('/<!--nextpage-->([^<]*)<!--nexttitle-->/', $content, $m);
return implode(' / ', $m[1]);
}
// then you echo get_all_strings_between($content) where you need it
If I'm incorrect, please provide more info what are these nextpage and nexttitle tags? Are they appear like this literally?

Categories