this is probably a VERY stupid question but I'm a bit new into this so please help me out. I have written a mini code using instagram API that loads photos from a specific location, using the location id. Now what I want to achieve is that use this for a wordpress website i'm building that lists some hotels and restaurants. I've defined the location id as a custom field, so I need to use the following code to call it:
<?php echo get_post_meta($post->ID, 'Instagram', true); ?>
And my url to call the photos is the following:
<?php $result = fetchData("https://api.instagram.com/v1/locations/LOCATION-ID-HERE/media/recent/?access_token={$accessToken}&count=6");?>
The above code works if i insert a location id manually. What I want to achieve is insert the above code into the "location-id-here" part. I guess this is quite simple but I'm kind of confused as both are php functions.
Any help would be greatly appreciated!
The parameter you're putting in fetchData() is just a string, so you can concatenate output from another function into that string with the . operator:
<?php
$result = fetchData("https://api.instagram.com/v1/locations/" . get_post_meta($post->ID, 'Instagram', true) . "/media/recent/?access_token={$accessToken}&count=6");
?>
Related
I need to place my variable $theCompany into the end of a URI for a VoiceURI on Twilio. As you can see below I've managed to create the variable but I can't figure how to put it into the URI. When we submit the page the VoiceURI field in Twilio is www.ourdomain.com/.xml.
The same is also true for the xml file I'm trying to create which saves as $theCompany.xml
The code is below, help appreciated!
Here's the line I'm using to populate the VoiceURI in Twilio:
'VoiceUrl' => "http://www.ourdomain.com/$theCompany.xml",
And here's the line I'm using to save the xml file with a new name/ same name as passed from previous into Twilio
$doc->save('"$theCompany".xml');
It's probably really simple but this isn't my normal game, I'm more on the Infusionsoft side of things but the code and web guy is on Honeymoon!
Appreciate the assistance!
--EDIT--
Thanks for the answers so far, unfortunately they don't seem to be working. Here's the full code for the PHP xml creator:
<?php
session_start();
?>
<?php
$theCompany = $_SESSION['company'];
$doc = new DOMDocument( );
$ele = $doc->createElement( 'Root' );
$ele->nodeValue = 'This is a call for $_SESSION["company"] press any key to accept the call';
$doc->appendChild( $ele );
$doc->save("$theCompany.xml");
?>
I also need some help getting the $theCompany into the URL on the Buy Number PHP page seen below.
<?php
session_start();
?>
<?php
// this line loads the library
require('Services/Twilio.php');
$theCompany = $_SESSION['company'];
$account_sid = 'AC7841a99c892xxxbc8f7xxx';
$auth_token = 'a71cxx052080xx';
$client = new Services_Twilio($account_sid, $auth_token);
$phoneNumber = $client->account->incoming_phone_numbers->create(array(
'PhoneNumber' => $_SESSION["number"],
'VoiceUrl' => "http://www.ourdomain.com/"'$theCompany .'".xml",
));
echo $phoneNumber->sid;
?>
The pages follow like so:
1) We have a PHP page to find available numbers. This page then passes the information onto the PHP page (code directly above this one)
2) That page buys the number and adds it to the account along with the VoiceURI and once submitted the page passes to the XML creator page
I have a feeling I should switch the buy and xml pages around so we search for a number then create the XML file then buy the number but not sure if that matters?
Thanks for sticking with me!
--EDIT #2--
Hi guys, sorry about this I know you're all helping best you can. I'm still having trouble with this so I'm thinking it might be best to create the XML file and pass that as a variable to the PHP file that sends info into Twilio. If we were to create the XML with $doc->save($theCompany.'.xml'); how would we pass that as a variable to the next page in place of $doc->save($theCompany.'.xml');?
I think it makes more sense to create the variables then to add them in place of the URI which is attempting to be a hybrid of static and dynamic.
So I'd be looking at something like this:
$phoneNumber = $client->account->incoming_phone_numbers->create(array(
'PhoneNumber' => $_SESSION["number"],
'VoiceUrl' => $theXML,
));
Do you think that's a better option to the route I'm taking now?
Use this
$doc->save($theCompany.".xml");
If I haven't misunderstood, this seems like a really simple problem.
Either you can write variables in a string using double quotes, like this:
$doc->save("$theCompany.xml");
Or you use single quotes for clarity, making it easier to look at:
$doc->save($theCompany . '.xml');
On your first code bit you wrote this:
$ele->nodeValue = 'This is a call for $_SESSION["company"] press any key to accept the call';
You have to make sure the session variable is escaped, like this:
$ele->nodeValue = 'This is a call for ' . $_SESSION["company"] . ' press any key to accept the call';
And for your second code bit, your phoneNumber variable has to be properly escaped:
$phoneNumber = $client->account->incoming_phone_numbers->create(array(
'PhoneNumber' => $_SESSION["number"],
'VoiceUrl' => 'http://www.ourdomain.com/' . $theCompany . '.xml',
));
Ok so I have the code for a form that is called and works but it needs two varibles grabbed from the string of a url. I have the first and the second is the same for what im doing on any page that I am creating which is alot. Here is the code at the url: collabedit.com/9g99j
Question if Get <?php echo $_GET['id']; ?> is grabbing my id string from the url how do I use this in the echo of my function I just defined at the bottom of the code? Instead of having this: echo DescriptionGet(1256124, 50874); can someone tell me how to put something like this: echo DescriptionGet(1256124, $id);
This would make it so i dont' have to enter that id value for every page I want to create.
Thanks,
Thanks everyone for your replies and I was able to figure it out on my own and actually used exactly what the first reply was.
Now I have a new question about this function. How do I make it grab the image from that same page its grabbing the form code from? I can't figure this part out and its keeping me from doing mass automation for this site.
Anyone help?
Try this:
$id = $_GET['id'];
echo DescriptionGet(1256124, $id);
You can change your function definition from:
function DescriptionGet($c, $id)
to
function DescriptionGet($c, $id=50874)
Each time when you will call DescriptionGet($c) it will behave as you passed $id=50874 but also if you need you can call DescriptionGet($c, 20) and $id in the function will be set to 20.
And in case you want to simple use $_GET['id'] as function parameter you can simple run
echo DescriptionGet(1256124, intval($_GET['id']));
you don't even need to use extra variable.
I'm currently using this code:
$blog= file_get_contents("http://powback.tumblr.com/post/" . $post);
echo $blog;
And it works. But tumblr has added a script that activates each time you enter a password-field. So my question is:
Can i remove certain parts with "file_get_contents"?
Or just remove everything above
anything will work!
Thank you for your help!
(could i possibly kill a whole div so it wont load at all?)
You could try something like this, assuming the div you are trying to remove has a specific id and/or class:
$blog= file_get_contents("http://powback.tumblr.com/post/" . $post);
$blog = preg_replace('!<div\s+id="div-id"\s+class="div-class">.*?</div>!is', '', $blog);
echo $blog;
The post I found this in (http://stackoverflow.com/questions/1114916/how-can-i-remove-an-html-element-and-its-contents-using-regex) notes that if there is a nested div, this will fail.
Regardless, preg_replace or regex is your best bet here.
Im having a really simple issue but iv looked around and cant debug it for some reason, can someone point me in the right direction??
I have a php script which dynamically generates a link
<?php
$id = 1;
echo "<a href='http://www.example.com/page.php?id='$id'>click link</a>"
?>
On example.php I have...
$userId = $_POST['id'];
then I insert $userId query...
?>
For some reason the Post vairable is not being cause by the example.php script I can see it in the URL at the top of the page but they wont make sweet passionate php love. Any thoughts? I will mention I am doing this from within an IFRAME however I tried it simply and got the same result :(
I think you mean, on page.php you have...
If that is the case, you are sending the id parameter in a GET, not a POST. To access it in your other page you need to use:
$userId = $_GET['id'];
your variable is in $userId = $_GET['id'];.
another problem is a mess with ' symbols: should be
echo "<a href='http://www.example.com/page.php?id=$id'>click link</a>"
Sorry, but you ar sending data via GET NOT POST
access it via $_GET['id'];
Hey guys, I'm using Twitter's PHP API, called twitterlibphp, and it works well, but there's one thing that I need to be able to initiate, which is the linking of URLs and #username replies. I already have the function for this written up correctly (it is called clickable_link($text);) and have tested it successfully. I am not too familiar with parts of twitterlibphp (link goes to source code), and I am not sure where to put the function clickable_link() in order to make URLs and #username's clickable. I hope that is enough information, thanks a lot.
EDIT:
In addition, I would like only one status to come up in the function GetFriendsTimeline(), right now 20 come up, is there any easy way to limit it to one?
I would extend the Twitter class and put the functionality in my own getUserTimeline method.
class MyTwitter extends Twitter
{
public function getUserTimeline()
{
$result = parent::getUserTimeline();
// Your functionality ...
return $result;
}
}
You don't need to put clickable_link() in twitterlibphp. Instead, call it right before you output a status message. Example:
$twitter = new Twitter('username', 'password');
$result = $twitter->getUserTimeline();
... parse the $result XML here ...
echo 'Status : '.clickable_link($status);