Solved

PHP echo question LIMIT output

Posted on 2011-09-28
2
212 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
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 108

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to count occurrences of each item in an array.

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now