rabid lemming Posted July 22, 2006 Share Posted July 22, 2006 Hey ya all ;DI 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]<?phptry { $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 !? ??? Quote Link to comment https://forums.phpfreaks.com/topic/15333-is-this-php-code-right-aspnet-to-php-conversion/ Share on other sites More sharing options...
shocker-z Posted July 22, 2006 Share Posted July 22, 2006 Is 'try' ment to be a function? if so then you need this[code]<?phpfunction 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 Link to comment https://forums.phpfreaks.com/topic/15333-is-this-php-code-right-aspnet-to-php-conversion/#findComment-62065 Share on other sites More sharing options...
Joe Haley Posted July 22, 2006 Share Posted July 22, 2006 [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.phpYou need PHP 5 to use try / catch blocks and exceptions. Quote Link to comment https://forums.phpfreaks.com/topic/15333-is-this-php-code-right-aspnet-to-php-conversion/#findComment-62069 Share on other sites More sharing options...
shocker-z Posted July 22, 2006 Share Posted July 22, 2006 ahh ok sorry lol never ever seen anyone use 'try' in there code :-[ im on PHP 4 not 5 also so not come across it..Will leave you in peace now lolLiam Quote Link to comment https://forums.phpfreaks.com/topic/15333-is-this-php-code-right-aspnet-to-php-conversion/#findComment-62071 Share on other sites More sharing options...
wildteen88 Posted July 22, 2006 Share Posted July 22, 2006 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 Link to comment https://forums.phpfreaks.com/topic/15333-is-this-php-code-right-aspnet-to-php-conversion/#findComment-62078 Share on other sites More sharing options...
Barand Posted July 22, 2006 Share Posted July 22, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/15333-is-this-php-code-right-aspnet-to-php-conversion/#findComment-62119 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.