Jump to content

Recommended Posts

Hey ya all  ;D

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());
}
?>
[/code]

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>[/code]

Can any one tell me what I’m missing as far as i can see it all seams ok !?  ???
Is 'try' ment to be a function? if so then you need this

[code]<?php
function 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());
}
?>[/code]
[quote author=shocker-z link=topic=101472.msg401664#msg401664 date=1153578466]
Is 'try' ment to be a function? if so then you need this
[/quote]

you are WAY off.

http://php.net/manual/en/language.exceptions.php

You need PHP 5 to use try / catch blocks and exceptions.
Change:
[code]preg_match($GetTheRegularExpressionString, $GetTheStringToValidateString) == true[/code]
To just:
[code]$GetTheRegularExpressionString == $GetTheStringToValidateString[/code]

Also you cannot use header when you output something to the browser, here:
[code]print "dat=opps"; // connot oputput this, before you use header!
$URL="RegularExpressionsHTMLVersion.aspx";
header ("Location: $URL");[/code]
[quote]$GetTheRegularExpressionString = $_POST['TheRegularExpression'];
$GetTheStringToValidateString = $_POST['TheString'];
if ((isset($GetTheRegularExpressionString) == true) && (isset($GetTheStringToValidateString) == true)) {[/quote]

You cannot use isset() here as it will always return true, since the variables were set on the 2 previous lines.

Use

[code]if (!empty($GetTheRegularExpressionString) && !empty($GetTheStringToValidateString) ) {[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.