LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2007, 12:00 PM   #1
zybot5785
LQ Newbie
 
Registered: Apr 2007
Posts: 5

Rep: Reputation: 0
bash to php


grep $(echo "ab-c:de:f" | sed -e "s/[^0-9a-zA-Z]//g") filename.txt

I need this line to be converted to PHP only. the 'echo "ab-c:de:f" ' is going to be data filled in an input box from a form then php is going to take it and strip anything out that is not numberic or alphabetical and search the file from there. It would also be helpful if searches less than and greater than 6 characters (from the output of this command of course) were invalid searches.
 
Old 04-10-2007, 01:01 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
http://www.php.net/manual/en/ref.strings.php
http://www.php.net/manual/en/ref.pcre.php
 
Old 04-10-2007, 02:07 PM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi
Code:
echo "ab-c:de:f" | sed -e "s/[^0-9a-zA-Z]//g"
abcdef
The sed removes the "-" and ":" - did you intend it?

Anyway, to remove unwanted characters:
Code:
$safe = ereg_replace('[^0-9a-zA-Z]','',$unsafe);
To check if the length is 6:
Code:
if (strlen($safe) != 6)
  die("invalid search");
 
Old 04-10-2007, 02:44 PM   #4
zybot5785
LQ Newbie
 
Registered: Apr 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks much! Yes, I intentionally removed the : and -'s, I did not want any other characters in the file except 0-9 and A-Z.

I will test the code when I have a chance.

Thanks again!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php and bash script permissions paddyjoy Programming 2 10-04-2006 06:01 PM
Running bash commands from php. rookiepaul Linux - General 3 03-22-2006 02:22 AM
html/php frontend for bash rookiepaul Linux - General 5 03-05-2006 03:20 PM
PHP + bash: grep, cut or explode ???? :S ALInux Programming 3 12-13-2005 01:11 PM
Pass Parameters to php from bash iman00b Linux - Newbie 2 09-09-2004 05:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration