String Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kevinridge
    New Member
    • Feb 2008
    • 1

    String Question

    Hello,
    I have confusing string question. I have a string like this (example):

    [PHP]
    <?php $a = "
    {FILE: hello}
    hello contents
    {FILE: hello2}
    hello2 contents
    "; ?>
    [/PHP]


    What im trying to do is when the code reads {FILE: *} <- it makes that file. Than it puts all the contents in the file until it finds another {FILE: *} or the end of the string.

    I am sort of lost in the right direction to do this. Any sort of help would be great!

    Kev
  • Amzul
    New Member
    • Oct 2007
    • 130

    #2
    Originally posted by kevinridge
    Hello,
    I have confusing string question. I have a string like this (example):

    [PHP]
    <?php $a = "
    {FILE: hello}
    hello contents
    {FILE: hello2}
    hello2 contents
    "; ?>
    [/PHP]


    What im trying to do is when the code reads {FILE: *} <- it makes that file. Than it puts all the contents in the file until it finds another {FILE: *} or the end of the string.

    I am sort of lost in the right direction to do this. Any sort of help would be great!

    Kev
    first i have to say that i dont think php is the right tool for that, use awk or sed,
    with php u need to use
    strpos
    preg_split
    fopen family
    explode
    i wouled use strpos to get the position of "{" and then explode the string between first "{" to "}" then array all the rest of the string from "}" to "{"

    take that array and use the fopen function to create the file with the name u want.

    i am sure theat this is not very efficient

    Comment

    Working...