1

I have an API result in this page How to print for example: annually price of product that it's id = 68 (first one) (in this case annually price is 500000.00 ) in another php file? this is an internal api of whmcs. thank you

Array
(
  [result] => success
  [totalresults] => 4
  [products] => Array
    (
      [product] => Array
        (
          [0] => Array
            (
              [pid] => 68
              [gid] => 16
              [type] => hostingaccount
              [name] => IR-CL100
              [description] => <li>حجم دیسک<strong>۱۰۰ مگابایت</strong></li>
<li>ترنسفر ماهیانه<strong>۲ گیگابایت</strong></li>
<li>پارک دومین <strong>رایگان</strong></li>
<li>دومین افزوده<strong>۱۰/۰۰۰ تومان</strong></li>
<li>تعداد MySQL<strong>۱ عدد</strong></li>

              [module] => directadmin
              [paytype] => recurring
              [pricing] => Array
                (
                  [IRR] => Array
                    (
                      [prefix] => 
                      [suffix] =>  ریال
                      [msetupfee] => 100000.00
                      [qsetupfee] => 50000.00
                      [ssetupfee] => 0.00
                      [asetupfee] => 0.00
                      [bsetupfee] => 0.00
                      [tsetupfee] => 0.00
                      [monthly] => 50000.00
                      [quarterly] => 150000.00
                      [semiannually] => 300000.00
                      [annually] => 500000.00
                      [biennially] => 900000.00
                      [triennially] => -1.00
                    )

                )

              [customfields] => Array
                (
                  [customfield] => Array
                    (
                    )

                )

              [configoptions] => Array
                (
                  [configoption] => Array
                    (
                      [0] => Array
                        (
                          [id] => 31
                          [name] => سایت افزوده
                          [type] => 4
                          [options] => Array
                            (
                              [option] => Array
                                (
                                  [0] => Array
                                    (
                                      [id] => 59
                                      [name] => سایت افزوده - میزبانی بیش از یک سایت در یک حساب کاربری
                                      [recurring] => 
                                      [pricing] => Array
                                        (
                                          [IRR] => Array
                                            (
                                              [msetupfee] => 50000.00
                                              [qsetupfee] => 0.00
                                              [ssetupfee] => 0.00
                                              [asetupfee] => 0.00
                                              [bsetupfee] => 0.00
                                              [tsetupfee] => 0.00
                                              [monthly] => 10000.00
                                              [quarterly] => 30000.00
                                              [semiannually] => 60000.00
                                              [annually] => 100000.00
                                              [biennially] => 200000.00
                                              [triennially] => 300000.00
                                            )

                                        )

                                    )

                                )

                            )

                        )

                      [1] => Array
                        (
                          [id] => 63
                          [name] => دیسک اضافی
                          [type] => 4
                          [options] => Array
                            (
                              [option] => Array
                                (
                                  [0] => Array
                                    (
                                      [id] => 166
                                      [name] => گیگابایت دیسک اضافی
                                      [recurring] => 
                                      [pricing] => Array
                                        (
                                          [IRR] => Array
                                            (
                                              [msetupfee] => 50000.00
                                              [qsetupfee] => 0.00
                                              [ssetupfee] => 0.00
                                              [asetupfee] => 0.00
                                              [bsetupfee] => 0.00
                                              [tsetupfee] => 0.00
                                              [monthly] => 100000.00
                                              [quarterly] => 300000.00
                                              [semiannually] => 600000.00
                                              [annually] => 1200000.00
                                              [biennially] => 2400000.00
                                              [triennially] => 3600000.00
                                            )

                                        )

                                    )

                                )

                            )

                        )

                      [2] => Array
                        (
                          [id] => 33
                          [name] => پهنای باند اضافه
                          [type] => 4
                          [options] => Array
                            (
                              [option] => Array
                                (
                                  [0] => Array
                                    (
                                      [id] => 61
                                      [name] => ۱۰ گیگابایت ترنسفر ماهیانه برای سایت های پر بازدید
                                      [recurring] => 
                                      [pricing] => Array
                                        (
                                          [IRR] => Array
                                            (
                                              [msetupfee] => 50000.00
                                              [qsetupfee] => 0.00
                                              [ssetupfee] => 0.00
                                              [asetupfee] => 0.00
                                              [bsetupfee] => 0.00
                                              [tsetupfee] => 0.00
                                              [monthly] => 50000.00
                                              [quarterly] => 150000.00
                                              [semiannually] => 300000.00
                                              [annually] => 600000.00
                                              [biennially] => 1200000.00
                                              [triennially] => 1800000.00
                                            )

                                        )

                                    )

                                )

                            )

                        )

                    )

                )

            )

        )

    )

)
7
  • You can use $_SESSION variable to store this result and fetch in another page. Commented Mar 18, 2017 at 1:29
  • this "API" is returning the results of a print_r. Is there a way u can modify that so that it returns JSON instead? Commented Mar 18, 2017 at 1:31
  • Possible duplicate of PHP how to retrieve array values Commented Mar 18, 2017 at 1:37
  • Thanks. yes. How to modify that to make return json instead? @CodeGodie Commented Mar 18, 2017 at 1:39
  • header('Content-Type: application/json'); echo json_encode($array); Commented Mar 18, 2017 at 1:49

1 Answer 1

0

The problem is that your API is returning the contents of print_r, it should instead return JSON:

do this:

header('Content-Type: application/json'); 
echo json_encode($array);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.