There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Wild char IF


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
vipernet's Avatar
Senior Member with 109 posts.
 
Join Date: Aug 2007
20-May-2008, 09:45 AM #1
Wild char IF
Never really done this before so kind of new with it all. I tried to find an answer at php.net, no luck.

Here is the script that handles what I want to echo:

PHP Code:
$count $s ;

//Table within Loop
echo "<table border=\"1\" align=\"center\">";
echo 
"<tr><th>Item</th>";
echo 
"<th>System Name</th>";
echo 
"<th>Room</th>";
echo 
"<th>Brand</th>";
echo 
"<th>School</th>";
echo 
"<th>Sticker</th></tr>";

// now you can display the results returned
  
while ($rowmysql_fetch_array($result)) {
  
$title $row["item"];
  
$title2 $row["computer_name"];
  
$title3 $row["room"];
  
$title4 $row["brand"];
  
$title5 $row["school"];
  
$title6 $row["sticker"];
echo 
"<tr><td>";
echo 
"&nbsp;$title";
echo 
"</td><td>";
//echo "&nbsp;$title2";
if ($title== "printer")
  {
echo 
'<a href=" http://'.$title2.'" target="_blank">'.$title2.'</a>';
}
else
{
echo 
'<a href=" http://'.$title2.':5800" target="_blank">'.$title2.'</a>';

What i want is to be able to make the expression a wild char
PHP Code:
if ($title== "printer"
and echo the true/false statement
haswalt's Avatar
Computer Specs
Senior Member with 416 posts.
 
Join Date: Nov 2004
Location: South Coast, UK
Experience: Advanced
20-May-2008, 11:29 AM #2
er that doens't make any sense. If you make it a wildcard, then the if will always kick in.

but if you mean you want to use regulare expressions to match things then try this:

I'm not to hot on regex but will give it a go.

Say you have a string like this "test-printer-on-computer_a" and you want to match the word printer then you could try:

PHP Code:

if (preg_match('/printer/i'$title)) 
  { 
echo 
'<a href=" http://'.$title2.'" target="_blank">'.$title2.'</a>'

else 

echo 
'<a href=" http://'.$title2.':5800" target="_blank">'.$title2.'</a>'

__________________
LQD Internet Limited
We've just got better! With the launch of our new site we have SLASHED our prices and upped the offering. Check it out!

10% Discount for ALL Tech Support Guy Members
Simply use the promo code of "T3CHGUY" when ordering to recieve your 10% discount on all shared and reseller hosting packages.
vipernet's Avatar
Senior Member with 109 posts.
 
Join Date: Aug 2007
20-May-2008, 01:31 PM #3
awesome dude, worked like a champ.

Sorry I wasn't descriptive in my last post.

Within the SQL database the text within the fields are (printer, color printer, desktop, laptop...etc) so i wanted to filter them using a common word = printer.
Big-K's Avatar
Distinguished Member with 6,883 posts.
 
Join Date: Nov 2003
Location: Kansas
Experience: Advanced
20-May-2008, 02:10 PM #4
well if your gonna do that then why use the regex engine? Its far slower than the native php functions like, say, strpos

$string = "I am the most awesome person ever";
if(strpos($string,"awesome")) echo "im so awesome";

this if will fire because the strpos function found the word 'awesome' in the phrase. Just remember though, that strpos has the arguements 'haystack' THEN 'needle', as opposed to most string functions.
TroyTime's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Apr 2008
Experience: programmer for 10 years, but new to vista
20-May-2008, 02:48 PM #5
Quote:
Originally Posted by Big-K View Post
well if your gonna do that then why use the regex engine? Its far slower than the native php functions like, say, strpos

$string = "I am the most awesome person ever";
if(strpos($string,"awesome")) echo "im so awesome";

this if will fire because the strpos function found the word 'awesome' in the phrase. Just remember though, that strpos has the arguements 'haystack' THEN 'needle', as opposed to most string functions.
thank you. using regex for simple matching is a pet peeve of mine.
but then again, so is echoing a bunch of consecutive lines of html
?>
<your>
<html>
<here>
<? // is much more readable AND easier on the parser
Big-K's Avatar
Distinguished Member with 6,883 posts.
 
Join Date: Nov 2003
Location: Kansas
Experience: Advanced
26-May-2008, 03:25 AM #6
Another option would be

echo "<table border=\"1\" align=\"center\">
<tr><th>Item</th>
<th>System Name</th>
<th>Room</th
<th>Brand</th>
<th>School</th>
<th>Sticker</th></tr>";

Easier to read, somewhat easier on the parser(not as much as ending the tags though), and it gives you line breaks in 'view source'.

Also, the code i put up was wrong, the if statement would preferably be
if(strpos($string,"phrase") !== false){do action}
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:50 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.