<new line> matching problem

Discussion in 'PHP' started by stats, Jul 7, 2007.

  1. #1
    Hi

    I have a function getHtml($head, $tail, $page) which takes from an HTML page everything that is surrounded by $head and $tail

    however i have some situations where in $head i have to put up multy lines

    for example if the HTML looks like this

    
    <b>here is the link</b>
                 
                 <span class=big>http//www.link.com</span>
    <b>here is the image</b>
                 
                 <span class=big>http://www.link.com/image.jpg</span>
    
    
    HTML:
    in the code above, if i want to take only image, i have to put in my $head the exact same thing as it appears on the HTML above, like this

    <b>here is the image</b>
                 
                 <span class=big>
    HTML:
    Including the NEW LINES and all the spaces and/or tabs


    so .. now .. how can i assign the above thing to my $head variable ?

    if i write something like

    $head = "<b>here is the image</b>\n            \n          <span class=big>" 
    Code (markup):
    this simply doesn't work

    anybody knows a way of writing this kind of a thing ? how do i assign the above 3 lines to my variable keeping their structure ?

    Thanks!
     
    stats, Jul 7, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    if i'm following you correctly you just want to add a tab in there? if that's the case..

    
    echo "<pre>";
    echo "line one\n\tline two";
    echo "</pre>";
    
    PHP:
     
    ansi, Jul 7, 2007 IP
  3. stats

    stats Well-Known Member

    Messages:
    586
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    i'm not echo-ing .. i'm trying to assign those lines (including <new line>) to a variable
     
    stats, Jul 7, 2007 IP
  4. robi-bobi

    robi-bobi Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    why not:
    $head = "<b>here is the image</b>
                 
                 <span class=big>";
    Code (markup):
    ;)
     
    robi-bobi, Jul 8, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Just assign a variable instead of echoing it, in ansi's code. The \n character stands for a new line, and the \t for a vertical tab.

    
    $foo = "line one\n\tline two";
    
    PHP:
    Btw, to actually SEE the new line in the browser, you have to use the <br /> tag.

    
    $foo = "line one<br />\n\tline two";
    
    PHP:
     
    nico_swd, Jul 8, 2007 IP