|
-
Jul 22nd, 2006, 09:50 AM
#1
Thread Starter
Addicted Member
Is this php code right ? asp.net to php conversion
Hey ya all,
I am trying to convert to following asp.net code to php version.
My php code which always says there is a phase error on line 2 "Parse error: parse error in c:\program files\easyphp1-8\www\index.php on line 2" even if I remove line 2 and 16, 17 & 18
Code:
<?php
try {
$GetTheRegularExpressionString = $_POST['TheRegularExpression'];
$GetTheStringToValidateString = $_POST['TheString'];
if ((isset($GetTheRegularExpressionString) == true) && (isset($GetTheStringToValidateString) == true)) {
if (preg_match($GetTheRegularExpressionString, $GetTheStringToValidateString) == true) {
print "dat=true";
} else {
print "dat=false";
}
} else {
print "dat=opps";
$URL="RegularExpressionsHTMLVersion.aspx";
header ("Location: $URL");
}
} catch (Exception $exception) {
print ("dat=" + $exception->getMessage()."\n".$error->getDebugInfo());
}
?>
My asp.net code:
Code:
<%@ Import NameSpace="System" %>
<%@ Import NameSpace="System.Net" %>
<%@ Import NameSpace="System.IO" %>
<%@ Import NameSpace="System.Text.RegularExpressions" %>
<%@ Page Language="VB" Debug="true" validateRequest="false" AutoEventWireup="true" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
' check page isn't been post back from form event procedures
Try
Dim GetTheRegularExpressionString As String = New String(Request.Form("TheRegularExpression"))
Dim GetTheStringToValidateString As String = New String(Request.Form("TheString"))
If GetTheRegularExpressionString.Length <> 0 And GetTheStringToValidateString.Length <> 0 Then
Dim StringRegex As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(GetTheRegularExpressionString)
If StringRegex.Match(GetTheStringToValidateString).Success = True Then
Response.Write("dat=True")
Else
Response.Write("dat=False")
End If
Else
Response.Write("dat=False")
Response.Redirect("RegularExpressionsHTMLVersion.aspx")
End If
Catch ex As Exception
Response.Write("dat=" & ex.ToString)
End Try
End Sub
</script>
Can any one tell me what I’m missing as far as i can see it all seams ok !?

I will wait for death with a smile and a big stick
-
Jul 22nd, 2006, 03:43 PM
#2
Re: Is this php code right ? asp.net to php conversion
Very descriptive variable names.
Are you sure you're running PHP5? PHP4 doesn't have try ... catch.
Not that it matters. Nothing you call within the try block throws. It's all legacy stuff, so it isn't exception-aware. It uses the old PHP error reporting.
As a side note, your code is invalid HTTP. The value of the Location header must be an absolute URL, including protocol and domain.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 29th, 2006, 12:07 PM
#3
Fanatic Member
Re: Is this php code right ? asp.net to php conversion
That looks like a lot of effort for a small amount of gain... or is it jsut me miss reading things.
-
Aug 2nd, 2006, 05:37 PM
#4
Thread Starter
Addicted Member
Re: Is this php code right ? asp.net to php conversion
Hey,
Well my pc hard drive has died on me, I am in a cyber café writing this, thanks for your help guys, when and if i ever fix my old pc, ill come back here and re-post the question, I used easy php 8 so sure that used php version 5 code, I am a novice at php as i'm more an asp.net person so
As a side note, your code is invalid HTTP. The value of the Location header must be an absolute URL, including protocol and domain.
not sure what that really means as the try and catch code dose work i have used it in other php scripts like this that work fine but not this for some reason. I'm not after a php script that’s going to be used front end wise, its just a back end script to work in-conjunction with flash so, just has to work and do the job lol ? So the descriptive names for the variables is just for my benefit and meant to be helpful for others who wont no the script to understand it more easily.
All I want is to be able to call a php page and get it to match a regular expression method against a string and return a result, so that’s why theirs a lot of effort for a small amount of gain as flash cant do this it self so have to do it with back end script. I made the script my self from scratch and just need it to work, nothing fancy, just to be robust and to do the job lol ? I can do it with the asp.net code but I need a php version as some servers don’t support asp.net.
Any help welcome
Last edited by rabid lemming; Aug 2nd, 2006 at 05:41 PM.

I will wait for death with a smile and a big stick
-
Aug 2nd, 2006, 11:32 PM
#5
Re: Is this php code right ? asp.net to php conversion
It is immaterial what editor you use, if you write PHP 5 code you still need PHP 5 to run it. You can check what version you have by making a blank page and calling the phpinfo() function on it.
-
Aug 4th, 2006, 05:09 PM
#6
Thread Starter
Addicted Member
Re: Is this php code right ? asp.net to php conversion
Hey ya,
Untill I fix my pc won't no for sure, but untill then dose the code at least look right or ok ? I'll try and upload and test the code asap and come back here if it dosn't work
cheers
RL

I will wait for death with a smile and a big stick
-
Aug 5th, 2006, 04:30 AM
#7
Re: Is this php code right ? asp.net to php conversion
Well, it looks alright, but, as CB said, the try{}...catch{} block is pointless, the only function you call is preg_match() and that does not throw exceptions.
Standard PHP generally as a rule doesn't throw many, if any, exceptions. If you need graceful error handling you can register an error handler function, but correctly written code doesn't produce errors anyway. Error handling is only really useful with things like plugin systems where the quality of code is unknown.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|