2
4

2 に答える 2

2

If i understand you correctly you need the all text here which is before ♥ you can use strpos

$stopper = '♥';
$string = 'text here

♥ text1
♥ text2
♥ text3

some more text here' ;
$final = trim(substr($string,0,strpos($string, $stopper)));
var_dump($final);

Output

string 'text here' (length=9)

Please note that your $stopper can also be \n new line

于 2012-11-11T15:36:10.250 に答える
0

the solution was:

  1. Do a str_replace on an array to target and remove specific portions of text.
  2. Create a regex and define acceptable values.
  3. Do a preg_replace on non-acceptable values.

this resulted in all the desired values being shown without instances of non-acceptable characters.

the code for the last two steps is below:

// this is the original external source

$part_one = $external_source; 

// create a regex

$regex
= '~'
. '['
. '^'
. 'A-Z'
. '0-9'
. ' '
. '!_:/,.#$-'
. ']'
. '~'
. 'i'
;

// clean the string

$part_one_cleaned = preg_replace($regex, NULL, $part_one);
于 2012-11-12T16:11:58.683 に答える