Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Find and cut string

    Hi,

    I'm new to PHP, so please bear with me! =)

    Is there a nice little function to find a string between to html-tags?
    I.e. let's say I have a string with the following text:
    "Hello world, <b>this is a test</b>"
    I would like to cut out the text between the <b> and </b> ("this is a test").

    Thanks in advance!
    Best regards
    Ola Ekedahl Guest

  2. Similar Questions and Discussions

    1. can't find string with quotes
      I'm trying to search for a string that contains quotes and my find statement keeps returning 0 even though I know the string exists in my...
    2. How to find second occurence of a string?
      Hi i am using the find function which will search the first occurence of a string. but how we can find the second or third ...occurence of the...
    3. [PHP] find string
      Isn't there an in_array function you can use? If (in_array($action, array(a1,a2,a3,a4)) { // do something } else { // do something else }
    4. find in string
      How can i count the number of times a string appears within another string. Thanks a...
    5. find string between files
      Hi all, how can I search for a specific string inside a directory (between files) ? Thanks for your help
  3. #2

    Default Re: Find and cut string

    In article <5cb8d6d1.0311230512.b02ff6f@posting.google.com> ,
    [email]ola@ekedahl.nu[/email] (Ola Ekedahl) wrote:
    > Is there a nice little function to find a string between to html-tags?
    > I.e. let's say I have a string with the following text:
    > "Hello world, <b>this is a test</b>"
    > I would like to cut out the text between the <b> and </b> ("this is a test").
    Here are two ways, one with preg_match and one with list and split:

    <?
    $string = "Hello world, <b>this is a test</b>";
    preg_match('/<b>.*<\/b>/i', $string, $result);
    echo strip_tags($result[0]);
    ?>

    <?
    $string = "Hello world, <b>this is a test</b>";
    list($junk, $good) = split('<b>', $string);
    list($good, $junk) = split('</b>', $good);
    echo $good;
    ?>

    Both methods would get more complicated if the HTML gets more
    complicated.

    hth

    --
    Bulworth : [email]funha@fung.arg[/email] | My email address is ROT13 encoded, decode to mail
    --------------------------|--------------------------------------------------
    <http://www.phplabs.com/> | PHP scripts and thousands of webmaster resources!
    Senator Jay Billington Bulworth Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139