How to get array with PHP on Joomla? - php

I've been making a Joomla module. I've mostly been successful, but I have one question: how do you get the image_fulltext variable to contain the following?
{"image_intro":"","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/sampledata\/parks\/landscape\/800px_cradle_mountain_seen_from_barn_bluff.jpg","float_fulltext":"","image_fulltext_alt":"Konsultasi belajar","image_fulltext_caption":""}

This functionality can be found inside the PHP library see json_encode and json_decode.

Related

PHP - how to find the meta information of an internal/built-in method programmatically?

Is it possible to find the data about a built in method in PHP via code?
For example, we have array_key_exists() which is an internal method.
I want to find out the parameters in this function programatically. The reason is, there is an up coming interview, and I will have to write code on Notepad. There will not be any internet connection to see PHP documentation.
If I can get the information about built in methods via code, it will be really helpful.
Is it at all possible to print meta data of a function? I am not asking about user defined functions, but about PHP's built in functions.
Thanks a lot.
You are looking for Reflection i think:
$refFunc = new ReflectionFunction('preg_replace');
foreach( $refFunc->getParameters() as $param ){
print $param;
}
http://php.net/manual/de/class.reflectionfunction.php

PHP / Wordpress - Loading a remote XML file

How can a get a object variable from a remote XML file, for example this one ?
In PHP5 it works fine with simplexml_load_file(), but I need this to work in PHP 4 also. How can I do that?
Or is there any built-in WordPress function that can load xml files? I tried using the WP's SimplePie class, but I get a weird object variable (with incorectly named fields etc).
If you want to use the smipleXML functions in PHP4 include this class ( I have used it and it works like a charm)
http://www.phpclasses.org/package/4484-PHP-Load-XML-files-in-PHP-4-like-SimpleXML-extension.html

Is there a php function to turn an associative array into a bunch of request parameters?

I have an array of the form array( 'paramName1'=>'param1', 'paramName2'=>'param2', ...) and want to turn it into a request string of the form paramName1=param1&paramName2=param2&...
It's easy enough to write a function to do this myself, but I was wondering if php already had a function to do this built in?
Yes, and that is http_build_query(). It's only available in PHP 5 though so if you're still using PHP 4 you'll have to roll your own function.

Drupal theme() problem

I am trying to display a custom page the same as my search results page by re-using the theme functions and pre-processors built into the search module.
With an empty Drupal cache this works beautifully. I simple call
theme('search_results', $results, 'node' );
with a correctly popuated results array, and I get back formatted markup.
Great.
However, when the cache is not clear, the search module is not available and so the theme() call goes nowhere and returns an empty string.
I've tried drupal_load('module','search') which makes the module file available, but does not intialize its hook_theme.
Fixed it with the following:
function_exists('search_theme') or drupal_load('module','search');
function_exists('template_preprocess_search_results') or module_load_include('inc','search','search.pages');
I don't like it though.
For theming standard search results use these:
http://api.drupal.org/api/drupal/modules--search--search-result.tpl.php/6
http://api.drupal.org/api/drupal/modules--search--search-results.tpl.php/6

Passing $_GET[] parameters to a script with Jumi?

I am using Jumi to include a number of PHP scripts on Joomla! articles and it works great. The problem I am having is with passing variables (in the form of $_GET parameters) to a PHP script.
Lets say I have a script "index.php" and I wish to pass the $_GET[] parameter "var" with the value of "10". This would normally be accomplished by pointing to: index.php?var=10. How do "emulate" this functionality with Jumi? I was hoping it would be as simple as:
{jumi [directory/index.php] [var=10]}
The above syntax however is not correct.
Any input would be appreciated.
-- Nicholas
After some trial and error and guidance from the official Joomla! forums I did solve my problem. Rather than passing a true $_GET[] parameter you can pass a $jumi array and reference that.
I wanted to avoid having to rewrite much of my script so what I did was the following.
1) Make the Jumi call like this:
{jumi [directory/index.php] [value]}
2) In index.php:
if(isset($jumi[0]))
{
$_GET['PARAM_YOU_WANT_SET'] = $jumi[0];
}
This is a very simple example of a quick and easy way to emulate passing a $_GET[] parameter to a script using Jumi. This approach saved me a great deal of time because I didn't have to rewrite my controller.
-- Nicholas
This is an old thread I know but there is something that some people might want to know.
If you are wanting to use Jumi with extra parameters in a Module then Nicholas' tip won't work but there is a way to do it.
There is a "Code written" section of the module and a "Source of code" section.
Put the url/path to the file in the "Source of code" section and then define your variables in the "Code written" section...it will pass the variable to the source file before executing so it will do what is desired.

Categories