Results 1 to 7 of 7

Thread: Help with php code as string

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Help with php code as string

    Im building a program that helps edit php code. I defined the code like so
    OC = "<?php
    if (!isset($page_title)) $page_title=""PHP code and online MySQL database - example username password"";
    if (!isset($page_keywords)) $page_keywords=""free PHP code, mysql sql"";
    if (!isset($page_desc)) $page_desc=""FREE example PHP code and a MySQL database"";
    ?>
    <html>

    <head>
    <title><?php echo $page_title; ?></title>
    <meta NAME=""keywords"" CONTENT=""<?php echo $page_keywords; ?>"">
    <meta NAME=""description"" CONTENT=""<?php echo $page_desc; ?>"">
    <meta NAME=""Content-Language"" CONTENT=""english"">
    <meta name=""Revisit-after"" content=""56 days"">
    <meta name=""Distribution"" content=""Global"">
    <meta name=""Copyright"" content=""Copyright © 1996-2008 Seiretto.com"">
    <meta NAME=""ROBOTS"" CONTENT=""ALL"">
    <link rel=""stylesheet"" type=""text/css"" href=""tds.css"">
    </head>

    <body BACKGROUND=""DiscoverBack.gif""
    style=""
    SCROLLBAR-ARROW-COLOR: #BBCCFF;
    SCROLLBAR-TRACK-COLOR: #C9DAF7;
    SCROLLBAR-FACE-COLOR: #002163;""
    TOPMARGIN=""0"" LEFTMARGIN=""15"" MARGINWIDTH=""0"" MARGINHEIGHT=""0"">
    <div align=""center""><center>

    <table border=""0"" width=""100%"" cellspacing=""0"" cellpadding=""0"">
    <tr>
    <td width=""100%""><p align=""center""><img height=""2"" src=""line.gif"" width=""99%"" border=""0""
    alt=""PHP code examples with database connectivity""></td>
    </tr>
    <tr>
    <td width=""100%""><img height=""2"" src=""line.gif"" width=""99%"" border=""0""
    alt=""PHP code examples with database connectivity""><div align=""center""><center><table
    border=""0"" width=""98%"" cellspacing=""0"" cellpadding=""0"">
    <tr>
    <td width=""9%""><font face=""Comic Sans MS""><strong><big>&nbsp;PHP.TheDemoSite.co.uk</big></strong></font></td>
    <td><p align=""center""><small>Just examples of <b>PHP</b> code, linking to your <b>MySQL</b>
    database and JavaScript.<br>
    <a href=""index.php"">1. Home</a> | <a href=""thedatabase.php"">2. The Database</a> | <a
    href=""addauser.php"">3. Add a User</a> | <a href=""login.php"">4. Login</a> | <a
    href=""getyourowndbonline.php"">5. Get your db online</a></small></td>
    </tr>
    </table>
    </center></div></td>
    </tr>
    <tr>
    <td width=""100%""><p align=""center""><img height=""2"" src=""line.gif"" width=""99%"" border=""0""
    alt=""PHP code examples with database connectivity""><br>
    </td>
    </tr>
    </table>
    </center></div>
    <p align=""center""><i>Also, while here don't forget to have a look at <a href=""http://thedemosite.co.uk/phpformmailer/""><strong>phpFormMailer </strong>(easy to use PHP form mail - more secure than many cgi form mail</a>) </i></p>
    <? include(""hostscripts-12870.inc"");?>
    </table>

    <table border=""0"" width=""100%"">
    <tr>
    <td>"

    but i still get errors. help?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help with php code as string

    what error are you getting?
    vb6 or php?
    if you are trying to make all that text into a string, and unless it is on a single line, you either need to append it or use line continuations, in either case with required new line characters
    Code:
    OC = "<?php"
    OC = OC & "if (!isset($page_title)) $page_title=""PHP code and online MySQL database - example OC username password""; " & vbnewline 
    OC = OC & "if (!isset($page_keywords)) $page_keywords=""free PHP code, mysql sql"";" & vbnewline 
    OC = OC & "if (!isset($page_desc)) $page_desc=""FREE example PHP code and a MySQL database"";" & vbnewline 
    OC = OC & "?>"
    or
    Code:
    OC = "<?php" & _
    "if (!isset($page_title)) $page_title=""PHP code and online MySQL database - example OC username password""; " & vbNewLine & _
    "if (!isset($page_keywords)) $page_keywords=""free PHP code, mysql sql"";" & vbNewLine & _
    "if (!isset($page_desc)) $page_desc=""FREE example PHP code and a MySQL database"";" & vbNewLine & _
    "?>"
    php does not care about the newlines, except to make it readable
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Re: Help with php code as string

    I am using this code
    Text1 = Replace(Text2, vbCrLf, vbCrLf & """ & vbNewLine & _")

    Instead of getting
    codecodecodecode & Vbnewline
    i get
    &Vbnewline codecodecode

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Help with php code as string

    You do not need to create new threads when you are basically handling the same problem. Your post here is practically the same as post #7 in this thread http://www.vbforums.com/showthread.php?t=627420

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Re: Help with php code as string

    The other thread was dealing with new lines in specific, while this thread was made to see if people already had experience with this particular subject (php code as string) .

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Re: Help with php code as string

    Could i get it to read the php code from a .txt?

    This is what im trying to do...
    i want to make a program that will let me easily edit certain parts of the php code using the replace function. However, the php code is too long; it is multi-lined, so i need to add vb crlf to the end.

    Side question: Does it matter if certain parts of the code wrap? etc. php = <codedocoedkceokceokc
    codecodecode>
    instead of
    <codecodecode>

  7. #7
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Help with php code as string

    Where does it wrap? Wrapping is something a view that presents the data does, not part of the actual string. If there is a NewLine (carriage return) character between "<codedocoedkceokceokc" and "codecodecode>" then it's not a wrap, and it will matter.

    If the file is large, there are various ways of reading a file line by line. Then you can handle each line separately. Or you can do it in chunks, maybe read 20 lines at a time etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width