php - preg_match regex with specific string structure -


edit: receive user input can string. want flag strings have structure.

// flag $subject = 'name 1 : text / name 2 : text';  // flag $subject = 'name 1 : text / name 2 : text / name 3';  // flag $subject = 'name 3 / name 2 / name 3';  // not flag $subject = 'name 1 : text, name 2, text, name 3';  // not flag $subject = 'this string'; 

so flagging every string has @ least 1 forward slash. can done regular expression? thanks!

i might have misunderstood want, think might want (no regex):

<?php     $subject = 'name 1 : text / name 2 : text / name 3';      $subjectarray = array();     $explode = explode(' / ', $subject);     ($i = 0; $i < count($explode); $i++) {         list($name, $text) = explode(' : ', $explode[$i]);         $subjectarray[] = array(             'name' => $name,             'text' => $text         );     }     print_r($subjectarray); ?> 

which output:

array (     [0] => array         (             [name] => name 1             [text] => text         )      [1] => array         (             [name] => name 2             [text] => text         )      [2] => array         (             [name] => name 3             [text] =>          )  ) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -