Solved

PHP echo question LIMIT output

Posted on 2011-09-28
2
236 Views
Last Modified: 2012-08-13
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 * ?
0
Comment
Question by:pda4me
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 36718183
<?php 

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

?>

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36718816
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]);

http://php.net/manual/en/function.explode.php

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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question