Jump to content

jobbe

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

About jobbe

  • Birthday 11/05/1991

Contact Methods

  • Website URL
    http://jakobsens.org

Profile Information

  • Gender
    Male
  • Location
    Denmark

jobbe's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I have written a function which will replace a string like: with the following The problem with this function is that I cannot run this on the entire page, since it would just return the first button. So I need help. I need a function that will check a string of text for the following combination: {- some text -} And then replace that string with the output from the function. It's important that the content between {- and -} can be changed, since the content acts as "variables" for my function. <?PHP function replaceText($str){ $dat = explode('{-',$str); $dat = explode('-}',$dat[1]); $dat = explode('|',$dat[0]); foreach($dat as $id => $str){ $out = explode(':',$str); $new[$out[0]] = $out[1]; } if($new['type']=='button') return '<input type="button" class="button" href="popup.php?r='.$new['info'].'" value="'.$new['text'].'" />'; if($new['type']=='link') { $http = 'http://'; if($new['secure']=='yes') $http = 'https://'; return '<a class="button" href="'.$http.$new['link'].'" target="'.$new['target'].'">'.$new['text'].'</a>'; } } $str_1 = '{-type:button|info:item|text:Read more about item-}'; $str_2 = '{-type:link|target:blank|link:www.google.com|secure:no|text:Read more about item-}'; $str = $str_1.$str_2; echo replaceText($str_1).'<br />'; echo replaceText($str_2).'<br />'; echo replaceText($str).'<br />'; ?>
  2. Asuming the file looks something like this: then i would try: <?PHP $content = file('file.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach($content as $id => $line){ $tmp = explode('Goober',$line); $data[$id] = explode('"', $tmp[1], -1); } var_dump($data); ?> which outputs an array
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.