Solved

Simple PHP Script Question

Posted on 2009-04-03
33
943 Views
Last Modified: 2013-11-18
Hi all,

Hopefully a quick question for you. We're adding some scrolling text (a 'newsticker') to our website, and we want the text imported from an RSS feed. There is a section on the website we've been getting all the info from (attached in the pic) that says we can import from any source, and gives some directions (in their example they suggest using a PHP script). The whole link that we're following is www.mioplanet.com/rsc/newsticker_javascript.htm . We've got the scrolling text, just not displaying from the RSS feed source that we want.

The RSS feed is - http://www.highways.gov.uk/rssfeed/rss.xml

Problem is, we don't have any expertise in this area whatsoever, so we need someone to help direct us through to having this imported RSS feed scrolling around...

I know that's not particularly clear, but when you don't really understand yourself it's hard to explain it exactly! If you need further info, please just ask.

Many thanks for any help in advance,

Pete
php.JPG
0
Comment
Question by:PeteJThomas
  • 16
  • 12
  • 4
  • +1
33 Comments
 
LVL 2

Expert Comment

by:Unspoken1
ID: 24059418
add the marquee tag.
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24059462
Thanks for the response, but sorry, that means nothing to me? Any chance of a little more detail? As I said, I have NO experience whatsoever with this, I'm actually asking this question on behalf of the colleague that looks after our website...

Cheers!

Pete
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24064243
Hi, Pete.  It may be a very simple problem, so I will try to give you some code to use for the "myimportlib.php" that is described on their page.  Let me know what you find when you try it.  Back in a few minutes, ~Ray
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24065020

<?php // RAY_rss_to_scroller.php

error_reporting(E_ALL);
 

// GET THE TRAFFIC FEED

$xml = file_get_contents("http://www.highways.gov.uk/rssfeed/rss.xml");
 

// MAKE IT INTO AN OBJECT

$obj = SimpleXML_Load_string($xml);
 

// GET THE MAIN TITLE

$str = $obj->channel->title;

$str = trim((string)$obj->channel->title);
 

// ITERATE OVER THE OBJECT TO GATHER THE STRINGS FOR THE FEED

foreach ($obj->channel->item as $thing)

{

   $alink = trim((string)$thing->link);

   $title = trim((string)$thing->title);

   $pdate = trim((string)$thing->pubDate);
 

   if ($alink != '')

   {

      $str .= "&nbsp; $pdate &nbsp;<a target=\"_blank\" href=\"$alink\">$title</a>&nbsp; &nbsp;";

   }

   else

   {

      $str .= "&nbsp; $pdate &nbsp;$title&nbsp; &nbsp;";

   }

}
 

// PRINT THE STRING FOR THE SCROLLER

echo $str;

Open in new window

0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24065051
Hi Ray,

Excellent, that's exactly the sort of thing I was hoping for. I don't even pretend to understand it, but I'll get my colleague to try adding that and see what happens. She tried pasting the link itself but all you get is the link scrolling along... lol.

Won't be able to try it this weekend though, but hold that thought, I promise I'll come back to you as soon as it's tested if you don't mind?

Again, many thanks!

Pete
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24065089
You're welcome.  Please post back here with any questions.  I'll be away until Wednesday, but if I'm not here maybe one of the other EE folks can help out.

Best regards, ~Ray
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24070941
To expand on the marquee comment

The tag mentioned is
<marquee>text here</marquee>
But since you already have the text scrolling, it is not so interesting as the php to get the actual rss
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24071777
Personally, I liked the idea of a marquee tag, but not all browsers will support the marquee tag.
http://en.wikipedia.org/wiki/Marquee_tag

Of course, not all clients will have JavaScript working, either.  So we just do our best to "degrade gracefully."  Cheers, ~Ray
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24075038
Ok, I still can't test anything at the moment as my colleague is on leave, but just to clarify the points you've made -

Will using the marquee tag basically just mean that we need to 'copy and paste' the text, and manually update it whenever the feed changes?

And if that is the case, does the PHP script option allow the scrolling text to change whenever the feed does without the need for us to update it ourselves?

And lastly, is there any requirement for additional software or anything for the PHP script to work or to create it in the first place?

Apologies, scripting and web development of any kind is pretty far from my comfort zone... (and that's putting it politely!!)

Thanks very much for your posts, as soon as she's back I'll get it tested and go from there... :)

Pete
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24075257
Please be advised there are two parts to this question
1. Scroll text - your first post let me to believe you have this sorted
2. get the actual text - here is where Paseur's script came into play

So assuming Paseur's script works, you change it to reflect the scrolling only either by adding your existing scroll script which we have not seen or by wrapping the output in the marquee tags with a appropriate attributes for direction and speed

The line to change is

// PRINT THE STRING FOR THE SCROLLER
echo $str;

So for marquee:


// PRINT THE STRING FOR THE SCROLLER
echo '<marquee>'.$str.'</marquee>';
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24075410
Indeed, the website I posted (http://www.mioplanet.com/rsc/newsticker_javascript.htm) gives instructions on creating the news ticker in the first place, so all we're now trying to do is get the source of the 'news' to be an RSS feed, so the ticker shows the info from the feed, also as per their instructions. Where they say:

"The scrolling text can be imported from any source: RSS, XML or any other format.

For example, if you want to import data using PHP to convert it into a single HTML line to be displayed by the ticker, create a php script to import and convert the data, and include it directly in the DIV tag as follows: (in code snippet below)"

This would imply that we would use Paseur's script once saved as a .php, and just put it instead of the "myimportlib.php", no?

Again apologies, I'm probably just getting myself confused... O.o

Pete
<DIV ID="TICKER" STYLE="overflow:hidden; width:520px">

  <? include "myimportlib.php" ?>

</DIV>

<script type="text/javascript" src="webticker_lib.js" language="javascript"></script>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24075618
Yes that should work assuming the wrapping is ALSO a php and it can find the myimportlib.php which I assume is the name of Ray's script
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24075742
Ok good good, on the right track then - 1 (hopefully) last question, when creating this script, can we just copy and paste Ray's script into a txt file and rename it to a .php?

Or do we need some sort of php script editor software to do this?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24076470
Any text editor should be ok.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24110233
Finally made it back.  Yes - just copy and paste with notepad or any similar thing.  Put it in the right directory and name it as shown above.  Let us know what you get.  thanks, ~Ray
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24110308
Ok thanks very much guys, if you don't mind, this may stay open for a while, as my colleague now isn't back in until 20th. Alright for some eh? I promise I won't forget, and I WILL come back to you when she returns.

Many thanks again to both of you for your help so far,

Pete
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 19

Author Comment

by:PeteJThomas
ID: 24185295
Hi guys,

Kim is now back and we've tested this today - Unfortunately it doesn't seem to work. We've used the website's little bit of code, pointing to myimportlib.php which contains the code that Ray kindly wrote for us.

The result is a blank space where the scrolling text should be. If we mispell any part of the path to myimportlib.php, then we get the path scrolling along (so for e.g. "e:\myimportlib.phpw" would actually be scrolling along) so that part seems ok, but when the path is correct, we see nothing at all.

This is where it may get a little awkward as the site is created using Lotus Domino, so it's hard for me to show you exactly how we have it all...

Do you any thoughts, or possibly any method of troubleshooting this further to get to the bottom of where the problem is?

Many thanks for your patience,

Pete
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24226163
Hey, just checking if anyone is still monitoring this question or not? If not I will assign points for time spent and get it closed off, otherwise I would really appreciate a follow up!

I understand it was left a while and so interest has died, so this is just a check-in really. :)

Many thanks for the help offered so far,

Pete
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24228277
I think that segment of code works as a standalone script and so you might try it that way, then we can see if it is a path or permission issue of some sort.  It sounds like maybe the PHP echo statement is not getting processed, but that is just a guess at this point.
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24259304
Hi Ray!

Thanks for responding, again my apologies, I was on holiday for a week, just got back today!

How can I test this as a standalone script then? It seems you can't just execute a .php script? Or maybe I need to download some sort of app that will do that?

Sorry, scripting is really something I know nothing about whatsoever! If you can explain how I can test the script by itself, I'd really appreciate it!

Many thanks,

Pete
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24259948
Pete: I'm not sure I understand your configuration, so this may not be a perfect answer, but here goes.  

You have a valid URL on server that is able to parse PHP, right?  You can prove that by running a script - something that just creates some predictable output to the browser.  For example, you can go to this page and see the RSS scroller script in action:

http://www.laprbass.com/RAY_rss_to_scroller.php

You should be able to run that script on your server by opening a browser window and entering the URL where you have your copy of the script (probably named something like myimportlib.php).  It should give you equivalent output on your screen.

HTH, ~Ray
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24261105
Well I'm not really sure - For a start, just to confirm, when I go to your link, I see what's attached in the screenshot1 - Is that what I'm meant to see? No scrolling, and in separate lines as opposed to a single line?

Secondly, when I open a browser on the server, if I type the UNC path to myimportlib.php (which is literally e:\myimportlib.php) I'm prompted to specify an application to open the file with. I'm thinking that's probably because I'm using a UNC path rather than a URL, so when typing the URL, all I see is the contents of the script, as in screenshot2.

Does this mean we can't parse php??

I can see this is starting to move away from the original question, so I won't expect you to see this through if it seems we're miles off track! :)

Pete


screenshot1.JPG
screenshot2.JPG
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24261267
Regarding this: "Well I'm not really sure - For a start, just to confirm, when I go to your link, I see what's attached in the screenshot1 - Is that what I'm meant to see?"

The answer is, "Yes, that is what you would expect."  The scrolling is done by Javascript.  The data that goes into the scroller is extracted from the RSS feed and returned in a single line.

Regarding this: "path to myimportlib.php" - for any of this to work, you need to have the applications on a web server.  It sounds like you may have the application on a local server that does not support PHP.  There is nothing wrong with using a local server, so long as your local server is configured to work as if it is a web server and it has Apache or equivalent software and it is set up to run PHP.

So an important question is: Where is this web site hosted?

Before we take a fork into becoming server administrators (I hope you have some good ones nearby) please let me have a look at the code you've got calling this PHP script.  Refer back to the JPG in the original post and post your equivalent code that implements those instructions.  Thanks!
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24261705
Hi Ray,

Ok, some background - The site is hosted on our intranet server at our datacentre. It is not web facing, but is definitely a webserver, and it runs Lotus Domino, and is created in Domino Designer.

We have literally copied and pasted the scripts from the scroller website - One important thing to understand, is that we have no actual expertise in webdesign etc. My colleague is the Domino administrator, but primarily for the email and database side of Domino, and has been 'self taught' aspects of the other areas which were initially set up long ago by ex-employees.

An example of what we have is shown in the screenshots - The first shows the top of the code used to create the page itself, the other shows the result in a browser.

I'm hoping this will just give you some insight into the way this is being done...

And as for your comment about not supporting PHP, you're most likely right - We didn't know that it had to be configured to support PHP, and although we do use Apache on other web servers, it is not installed on this particular server.

I think the problem is, we read the suggestion on the scroller website about using a PHP script to insert the RSS feed, and took it a little too literally, thinking we could just bung this script in there and it would work... Maybe the question should've been more about how to get the same result within a Domino environment?

Pete
Domino-Designer.JPG
IntranetHomePage.JPG
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24261787
Yes, the Domino environment is a key issue here, and perhaps the central issue in getting this to work.

Let's see what happens if I host the script for you.  Let's replace that "include" tag with an IFRAME tag that points to the script on my server.  I do not know if this will work but we can try.

I'll check back later.  Please post back here with the results.  Thanks!
<iframe src="http://www.LAPRBass.com" 

scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0">

</iframe>

Open in new window

0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24261803
Oh and in case you're wondering, the second screenshot shows this RSS feed scrolling along, but this is no good - This was using a completely different scrolling text tool, contains adverts to "Mexican brides" that occasionally scroll past along with the traffic reports... -.- Obviously that is no good!!

This was only just implemented, and the reason for this question is that we're trying to find a better way of doing it, which we think we can do with the website mentioned at the start (www.mioplanet.com/rsc/newsticker_javascript.htm), provided we can get it to work...

Also, in screenshot 1, that is what was used to create the part of the page that displays the scroller we don't want. The 'test' page that is currently not working and using the script from www.mioplanet.com/rsc/newsticker_javascript.htm is shown in this screenshot -
Domino-Designer-2.JPG
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24261972
Ok, so here is the result of your suggestion -

Screenshot1 shows how the code looks now in Domino Designer...

Screenshot2 shows the resulting webpage (bare in mind that the 'image block' near the top of the page is slowly scrolling along from right to left!)

So we used a little common sense and assumed that you'd just missed the extra "/RAY_rss_to_scroller.php" on the end of the URL, and then we get what's shown in SCREENSHOT 3... (again, the 'block of text' is scrolling along)


Screenshot1.JPG
Screenshot2.JPG
Screenshot3.JPG
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24263962
"So we used a little common sense and assumed that you'd just missed the extra "/RAY_rss_to_scroller.php" on the end of the URL, "

Exactly - typical for the acknowledged King of All Typos.

"...and then we get what's shown in SCREENSHOT 3... (again, the 'block of text' is scrolling along)"

Sounds like it is getting closer!  At this point I think the only remaining issues will be solved by adjusting the size and shape of the IFRAME - and by putting the rss_to_ticker script on a PHP enabled server that you can use permanently.  Sorry I can't help with the Domino part of this.

The data coming out of the PHP script has no line feeds in it, so it is getting wrapped into that text block somehow, perhaps by CSS of the Domino code (I have no real clue here)?
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24268129
Many many thanks Ray! It does look like we're getting closer... I have one more thing I'd like your clarification on if possible. Following is a couple of paragraphs from an IBM article on PHP and Domino. It continues after these paragraphs to explain steps on setting it up. Can you just skim it and let me know if this sounds like what we're looking to do? I'm not sure of the terminology they use, like 'CGI standard' etc... And I'm not sure what they mean by PHP Version 5.0 or later - Is that defined by the 'script interpreter' that you install? Anyway -

"With the proper configuration, Lotus Domino can run PHP CGI programs on a Domino server. CGI support is support for the CGI standard and not for any particular script interpreter. This CGI support includes script interpreters that require the name of the input file, such as PHP. All script interpreters should be placed outside Domino as a basic security precaution. The assistance provided by IBM Technical Support is limited to configuring the Domino server and the documents in the Domino Directory required to run the CGI program.

To configure Domino to run PHP, use the steps below. These steps assume the PHP script resides within the domino\data\HTML folder and that the PHP version is 5.0 or later. They differ from the steps in the Domino Administrator 7 Help because those steps run PHP as an in-line executable rather than a script interpreter. These updated directions allow PHP to reside in the HTML folder with html files, which is common in PHP environments."

Mean anything to you?? :)

Pete
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24270401
Hi, Pete.  It means a little to me at a high-level view, but I am not much of a sysadmin type.

To me, it means you can use PHP if you install it correctly.  That is good news because it opens up a world of application opportunities.  I agree that you should use PHP5 and NOT PHP4.  I also think that this is an area where you should hire a professional.  Installing and configuring a major piece of software is not a good job for someone who is in unfamiliar territory.

Best of luck with it, ~Ray
0
 
LVL 19

Author Comment

by:PeteJThomas
ID: 24270468
Yeah, although I'm thinking at this point that maybe we should look into routes that don't involve PHP, simply because when you look at the overall picture, we're doing all this because some marketing bod thinks it would be nice to have traffic updates on our intranet page.

It all seems like a lot of work to get something relatively simple going...

Anyway, that's another story... Many thanks for all your time and help!

Pete
0
 
LVL 19

Author Closing Comment

by:PeteJThomas
ID: 31566207
Thanks for all the time, information and for your perseverance! Even if we don't go down that route it's all much appreciated!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24271136
Thanks for the points - it's a great question whatever the eventual outcome. Best, ~Ray
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now