Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6591247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:24:02+00:00 2026-05-25T17:24:02+00:00

I want to create a function using cURL and the bit.ly API to shorten

  • 0

I want to create a function using cURL and the bit.ly API to shorten links.

My question is, how can I get the string of data returned by cURL and continue to use it throughout the function (as this doesn’t seem to work, I’d assume due to the attempt to return $string and then use string in the rest of the function).

Here’s what I have, which just displays a blank page:

function shorten_url($bit_login,$bit_api,$long_url) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://api.bitly.com/v3/shorten?login=".$bit_login."&apiKey=".$bit_api."&longUrl=".$long_url."&format=xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);

return $string;

$xml = simplexml_load_string($string);
$short_url = $xml->data[0]->url;
echo $short_url;
}

shorten_url($login,$apikey,"http://www.google.com");

I’ve also tried to return $short_url and echo it ouside of the function, after the function is run (below shorten_url()), which doesn’t work either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:24:03+00:00Added an answer on May 25, 2026 at 5:24 pm

    The function will return NULL. You are missing the $string = curl_exec($ch);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a simple menu function which can call it example get_menu()
i want to create functions what get the folder size. I write small function:
I want to create a function that has a select query inside that can
I want to get one value from a function using a case statement. I
i want to create a function which calculates a value using a query and
I am want to create a javascript function using jQuery which will close the
Using this function I want to create a PHP navigation: function loadPage($pagename) { if
I want to create a function dynamically using javascript. I've started with the following:
I am using PostgreSQL 8.4 and I want to create a function that returns
I want to create tags using echo function but I'm stuck here; I dont

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.