Djoris
-
Posts
13 -
Joined
-
Last visited
Never
Posts posted by Djoris
-
-
Anybody an idea or a hint where I can get such info? Thanks!
-
Can you PM the XML file I'll make an attempt to solve this for you.
Thanks I just send you a PM.
-
I use the following code to output individual categories in the wordpress navigation:
<?php echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2>$3</a>',wp_list_categories('echo=1&orderby=id&title_li&include=1897')); ?>
This works great and gives the output:
<li class="cat-item cat-item-1897"><a href="http:www.test.org/category/category-name/">category</a></li>
For some categories I would like to add ?gpc_sortby=views to the end of the url. Does anybody know how I can change the preg replace to get this right.
Thanks!
-
What do you mean by "not working"? If you don't provide errors it seems like you don't want this solved.
I sure would like this problem to be solved. When I try to parse the simple xml, I don't get any output at all, not even an error message.
I spend a couple of days playing with the codes given in this thread but still don't get the comma's between the 'actors'. I tried the code:
<?php $data = file_get_contents("XML URL"); $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match); $str = implode(", ", $match[1]); echo $str; //echos actor#1, actor #2, actor #3 ?>
I think this should work but the preg match is not like it should be because the xml takes all the content between <actors></actors> and because the individual actors are also tagged it doesn't get it right:
<actors>
<actor id="1234">Actor #1</actor>
<actor id="12345">Actor #2</actor>
<actor id="123456">Actor #3</actor>
</actors>
I tried the preg match:
$actors = preg_match_all("/<actor>(.+)<\/actor>/", $data, $match);
But this doesn't give any output nor error messages. Anybody an idea how to get this right?
-
Yes I understand, but somehow simplexml is not working although I use php5 on my server..
-
Oke I changed $xml to $data, but this doesn't seem to be the solution because I get the warning Invalid argument supplied for foreach(). How can I define the $xml in your given code?
-
I tried all the above codes but they didn't work. The simple xml gives no output at all and the other options give the Warning: implode() [function.implode]: Invalid arguments passed in /home/../public_html/wp-content/themes/test/single.php on line 132.
I tried for example this:
$data = file_get_contents("XML URL"); $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match); foreach ($n_data->actor as $d) { $show[] = $d; } echo implode(", ", $show);
or this
$data = file_get_contents("XML URL"); // Build an array of actor names like array("Actor #1", "Actor #2", ...) $actors = array(); foreach ($xml->actor as $actor) { $actors[] = (string) $actor; } // Echo with commas echo implode(", ", $actors);
Any more tips would be appreciated. After that I promise I will buy a php book to avoid embarresing situations like this..
-
Thanks guys ! I am using php5, so to my knowledge SimpleXMl should be installed on default. Any more suggestions..?
-
Thanks for your suggestion to use simple xml. But somehow it isn't working, it is probably me being a newbie :'( or something with the external XML. Any suggestions would be more than welcome..
-
I am sorry that I gave the impression that I didn't try, because I did. Tried several options including this one:
<?php $data = file_get_contents("XML URL"); $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match); $str = implode(", ", $match[1]); foreach ($match[1] as $actors) { echo $str; //echos actor#1, actor #2, actor #3 } ?>
I will have a another look at the implode function, but of course any reply is welcome
-
Thanks for your quick reply. Can you help me a bit further and implemented in the original code I wrote? I don't know if it is necessary to mention, but the output with 'actor #1' is variable it could be also Brad Pitt or so.. Thanks
-
After a lot of lurking, thanks for all the great topics I now have a guestion where I could really use your help.
I am parsing some xml data with the following php:
<?php $data = file_get_contents("XML URL"); $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match); foreach ($match[1] as $actors) { echo $actors; } ?>
For the following XML part:
<actors>
<actor id="1234">Actor #1</actor>
<actor id="12345">Actor #2</actor>
<actor id="123456">Actor #3</actor>
</actors>
This gives the ouput: Actor #1 Actor #2 Actor #3
Now I would like to separate the actor names by comma, like this: Actor #1, Actor #2, Actor #3
Does anybody know how to modify the php code for this? Thanks
Wordpress list categories preg replace
in Applications
Posted
This topic was moved out of the php coding help forum, although it isn't particulair a WP topic. Can anybody please help me?