Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 05-14-2007, 10:31 AM   #1 (permalink)
vahagn
Recruit
 
Join Date: May 2007
Posts: 3
vahagn is on a distinguished road
Question Help with PHP code conversion to PERL

Hi!

I'm totally new to PHP and try to understand the syntax. Could anyone say what:

//Specify your URL
$URL = "http://www.exampleurl.com";

//Open a stream in READ mode
$handle = fopen ($URL, "r");

//It's this one I don't get
$key = str_replace(' ', '%20',fread($handle, 1000000));

converts into PERL? Can I rewrite this code syntax in PERL?

Thanks in advance,

/V
__________________
vahagn is offline   Reply With Quote
Old 05-14-2007, 11:38 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
summary: this code reads in the text of the web page exampleurl. com and replaces all spaces with %20.


//Specify your URL
$URL = "http://www.exampleurl.com";

$ before a string indicates a variable in PHP. this line of code just assigns example.url.com to the variable: $URL


//Open a stream in READ mode
$handle = fopen ($URL, "r");

The comment says it all.


//It's this one I don't get
$key = str_replace(' ', '%20',fread($handle, 1000000));

you're calling 2 functions here. fread() reads the resource you send in and returns a string up to 1000000 bytes.

str_replace() just replaces the first argument with the second argument in the string defined in the third argument.

to make it easier to understand, look at it like this:
PHP Code:
$buffer fread($handle1000000);

$key str_replace(' ''%20'$buffer); 
also, remember PHP: Hypertext Preprocessor is your friend. use their function search when you need more information as to what functions like str_replace() and fread() do. it's an awesome resource.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 05-14-2007, 11:37 PM   #3 (permalink)
vahagn
Recruit
 
Join Date: May 2007
Posts: 3
vahagn is on a distinguished road
Thanks!

You don't happen to know how this could be done in PERL, would you? I mean the part with openning an handle to an URL and reading its reply...
__________________
vahagn is offline   Reply With Quote
Old 05-15-2007, 07:48 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
sorry, no. just out of curiosity, what is the situation that you need it done in perl? is it to be used in a perl cgi web app or is it just a perl script?
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 05-15-2007, 10:35 AM   #5 (permalink)
vahagn
Recruit
 
Join Date: May 2007
Posts: 3
vahagn is on a distinguished road
It's a existing webshop written in PERL for which my friend wants to get an card-payment package. The company supports only ASP and PHP libraries and has examples for how the integration can be done. So what I need now is to convert this PHP code that they require to a PERL function call that reads the required URL call to the server, reads the replied answer and use it.
__________________
vahagn is offline   Reply With Quote
Old 05-15-2007, 08:09 PM   #6 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
in perl
Code:
use LWP::Simple; my $URL = "http://www.exampleurl.com"; my $content = get($URL); $content =~ s/ /%20/g;
Also perl isn't an acronym, so don't put it in all caps.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Perl Code fabbasey All Other Coding Languages 3 05-25-2005 03:17 PM
Simple PHP MySQL code: confused. easilyi Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 10-24-2004 07:53 PM
{perl} HTTP Error Code Response gty All Other Coding Languages 2 09-08-2004 11:09 AM
PHP code for Login Screen KEEBOD PHP 2 07-15-2004 05:18 PM
An Introduction to XHTML/CSS Rie HTML / CSS 0 03-07-2003 06:50 PM


All times are GMT -8. The time now is 05:02 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle