I am trying to get the name of the person who has posted the post, but I don't understand how to get the name from the array.
Here is the full code:
http://pastebin.com/88ADm5Uw
This is the line I have a problem with:
echo "FROM: " . print_r($post['from']) . '<br>';
This line returns two values(id and name) and I want to only print out the name. Please help!:
EDIT:
Any way to get the profile picture?
Try this:
echo "FROM: " . print_r($post['from']['name']) . '<br>';
You can see the complete JSON here:
https://developers.facebook.com/tools/explorer?method=GET&path=me%2Fhome
$post['from'] is an array containing name and id. If you only want to print out the name, you could do something like echo $post['from']['name'] I believe.
Related
On my custom Single product page, I want to link every value of pa_ontwerper to the correct page. I used this code what works if pa_ontwerper has only 1 value:
$ont = $product->get_attribute('pa_ontwerper');
echo "<a href='https://www.website.nl/attribute" . $ont . "/'>" . $ont . "</a>" ;
This results in: designer1 with link to www.website.nl/attribute/designer1/
But when pa_ontwerper has for example 2 values, the output wil show something like:
designer1,designer2 with a link to www.website.nl/attribute/designer1,designer2/
Which is wrong.
What can I change in the code to make sure both values are linked correcly?
i have a lang file with lots of pre-made statements
the one i'm working one is used as a template to email users
$lang['ADD_STORE_REQUEST_EMAIL_TITLE'] = " New store has been added";
as you guys can probably guessed, the code above is what would be the email title
my question is, how can i put variable in there? say i wanna have the email title as "hello john, new store has been added"
mail(ADMINISTRATOR_EMAIL,$lang['ADD_STORE_REQUEST_EMAIL_TITLE']"From: no-reply#gmail.com");
i tried adding the 'name' variable before and after the $lang, but it wont work. i tried appending it by name+$lang.... but still wont show up
You can do it like this:
$lang['ADD_STORE_REQUEST_EMAIL_TITLE'] = " New store".$yourVar." has been added";
or
$lang['ADD_STORE_REQUEST_EMAIL_TITLE'] = " New store has been added".$yourVar;
You can use the function sprintf to accomplish this.
Also. To concatenate strings in PHP, you need to use . instead of +
Ex:
mail('email#example.com', sprintf('This is a %s day', 'fine'), sprintf('Hello mr. %s', $name);
This will result in an email being sent to email#example.com with the subject "This is a fine day" and body "Hello mr. {some name from the variable"}
I have a google map on this page, all markers were generated by submit postcodes. So I have the array below, loop info of each marker,
imploded as ("array", "array") format, I am trying to click on a infoWindow and display the according marker details on details.php.
The problem is everything is on the button onclick event, only a simple get on the second page.
This is working, but it is a very bad way. Because the limit to URL length and security reasons;
I would like to be able to get an array info from details.php page,
and the button onclick event trigger url looks like: details.php?marker=id
I don't know what is the best way to go about this, can someone pointing me to the right direction please?
index.php
$info = array();
foreach($stmt as $x)
{
$info[] =
"<h4>" . $x['name'] . "</h4><hr />".
"<h5>Address: </h5>" . $x['Address']."<br />" .
"<h5>Postcode: " . $x['postcode'] ."</h5><br />" .
"<button onclick='window.location.href= \\\"details.php?marker=". "<h4>" . $x['name'] . "</h4><hr />".
"<h5>Address: </h5>" . $x['address']."<br />" . "<h5>Postcode: " . $x['postcode'] ."</h5><br />" . "\\\" ' >
View Details</button>";
}
$i=' "'.implode('","', $info).'"';
details.php
echo $infomarker = $_GET['marker'];
You have to use $x['id'] insted of $x['name'] which is unique in your database and also use base64_encode() for encryption of your id "details.php?marker=".base64_encode($x['id'])."
In your details.php
$infomarker = base64_decode($_GET['marker']);
Try using AJAX to get the info from details.php and then load it into your InfoWindow.
I didn't realise how simple this was, all I need is use that id, write it inside a sql statement in details page then call any part of the statement out. Thanks everyone. Thanks to #Manjeet Barnala for encode tips.
How to populate current page title (or current url) to the subject line via mailto?
Been using the code below as a starting point, obviously modifying the "Page Title Here" bit, but can't find a solution:
<?php echo "<a href='mailto:test#test.com" . $to . "?subject=Page Title Here" . $subject . "'>Send an email</a>";?>
Set page title to php var as
$title = 'Example';
and use it for
<title><?=$title;?></title>
and mail
<?php echo "<a href='mailto:test#test.com" . $to . "?subject=" . $title . $subject . "'>Send an email</a>";?>
This is not generically possible with PHP. PHP has no knowledge of what the page title is, or your HTML structure at all.
You will have to go to your code where you set the page title, and use that same variable in your e-mail. If this PHP code is handling a post from some page or something, you need that page title posted with your form data (which you can get with JavaScript document.title).
I have a standard HTML form on a WordPress post that the visitor will fill out. It consists of mostly checkboxes. What I would like, is after the form is submitted, a page is then presented to the user showing what they checked. For example, if the visitor checked off Checkbox A, B, and E, (but not C and D) then upon submission they would see the following:
You submitted:
Checkbox Value A
Checkbox Value B
Checkbox Value E
Obviously I can do this with just PHP, but my client would like to be able to modify the form options. Therefore I will need an easy to use backend.
Is there a plugin or user friendly way that this can be created? Or is my best bet to start building it myself?
the easiest way would be:
<pre>
<?php var_dump($_POST);?>
</pre>
but you can style it like:
<?php
foreach($_POST as $key=>$post_data){
echo "You posted:" . $key . " = " . $post_data . "<br>";
}
?>
Note that this might give errors if the $post_data type can't be displayed as a string, like an array in the POST data. This can be extended to:
<?php
foreach($_POST as $key=>$post_data){
if(is_array($post_data)){
echo "You posted:" . $key . " = " . print_r($post_data, true) . "<br>";
} else {
echo "You posted:" . $key . " = " . $post_data . "<br>";
}
}
?>
You can do something in jQuery.
$.post(
"post.php",
{checkbox : 1, checkbox2 : 0, checkbox3 : 0}, // this is the body of the post request
function(data) {
alert('page content: ' + data); // look up values in checkboxes and display them
}
);
Im not sure what kind of data wordpress needs, it might also need some session id to be sent if you need the user to be logged in.
If you wanna to show a json encoded list of the POST array is simple as
<?php echo json_encode($_POST);?>