PHP echo question LIMIT output

I have a column  in a table that has data like: B*3B as well as data like MEDH*001

I do an echo like this:

<?php echo(rawurlencode($row_WADAINMATE['CELL_ASSIGNMENT'])); ?>

Open in new window

How do I alter this echo to only display the characters prior to the * ?
Who is Participating?
Rik-LeggerConnect With a Mentor Commented:

echo(rawurlencode(preg_replace('/^(.*)\*.*$/', '$1', $row_WADAINMATE['CELL_ASSIGNMENT']))); 


Open in new window

Ray PaseurCommented:
I think the regex from Rik-Legger looks correct.  I would probably do it something like this:

$arr = explode('*', $row_WADAINMATE['CELL_ASSIGNMENT']);
echo rawurlencode($arr[0]);

There is also some combination of strpos() and substr() that would work, too.  Lots of ways to skin this cat!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.