Wikipedia:Reference desk/Archives/Computing/2008 March 22

From Wikipedia, the free encyclopedia

Computing desk
< March 21 << Feb | March | Apr >> March 23 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


Contents


[edit] March 22

[edit] Printing only the first 1000 characters/bytes in PHP

Hello! I'm trying to build a website, wherein a MySQL query would return me a really large text field. I need to print only the first few lines of this text. Is there some function in PHP that will select only the first 1000 characters or bytes from the text and display them? Any help would be appreciated. Thanks!--Seraphiel (talk) 06:00, 22 March 2008 (UTC)

You want substr(). Try
substr($the_string, 0, 1000); //that's characters 0 to 999, the first 1000 characters
:D\=< (talk) 06:03, 22 March 2008 (UTC)
Splendid! Exactly what I needed. Thank you!--Seraphiel (talk) 06:12, 22 March 2008 (UTC)

[edit] about hacking

i am using internet since last month,from last two days a messsage splash on my screen that your computer has been hacked and aal your vital information are sent though emails to other,it ask me to download that particular spyware tuo remove that virus hat can i do?

DO NOT DOWNLOAD IT! It's just an advertisement to trick you into downloading a spyware program. --grawity talk / PGP 09:51, 22 March 2008 (UTC)

If the OP is very distracted by the splash messages, maybe (s)he should get Adblock? What do you think, Grawity? Kushal 12:49, 22 March 2008 (UTC)

And Firefox. --grawity talk / PGP 14:30, 22 March 2008 (UTC)

No website is ever going to tell you, without you asking it to, whether you have a virus. (There are some online virus scanners, but that's the exception. They cannot run without you explicitly authorizing them to.) Pop-up ads of all sorts should be ignored, especially if they are of the "you have a virus/you are a winner/click here for a free gizmo" variety. Most up-to-date browsers have pop-up ads disabled by default for this reason. --Captain Ref Desk (talk) 16:45, 22 March 2008 (UTC)

I believe Captain meant "enabled" when he said "disabled". Kushal 19:18, 22 March 2008 (UTC)
No, I meant "disabled", as in, "most modern browsers block pop-ups by default." At least, I don't remember having to explicitly block them, but that might be my bad memory. Anyway, point being, on most up-to-date browsers you can block them very easily. :-) --Captain Ref Desk (talk) 19:38, 22 March 2008 (UTC)
If the messages appearing are in the form of a grey box with an "OK" button, you can switch them off entirely by following the instructions on this page--Kateshortforbob 17:23, 22 March 2008 (UTC).
If the internet can get directly to your computer on the windows messenger port, then you have much bigger problems.. buy a router :D\=< (talk) 21:04, 22 March 2008 (UTC)
After fixing this problem about 18 times for family/friends using elderly machines still on dial-up, it's kind of a Pavlovian response for me! --Kateshortforbob 00:07, 23 March 2008 (UTC)
The messenger service is disabled by default on XP SP2. If he's still operating pre-SP2 XP, *and* he doesn't have a router/firewall so messages can get through, he does have pretty serious problems. I'd kind of doubt that's it nowadays though, because of SP2. -- Consumed Crustacean (talk) 20:15, 23 March 2008 (UTC)

Hold on, I understand that we need to ask the OP if he has SP2. However, the way I see it, the message could just be a banner ad on myspace or something. Kushal 22:10, 23 March 2008 (UTC)

Yes, that sounds like a more likely explanation. It's also possible that he is infected with spyware; a common tactic for spyware is to redirect users to or a pop up a windows saying something along the lines of: "Your computer is infected; pay us $49.99 for SuperAntiSpywarePlusPlus and we'll get rid of it, guaranteed!". I have actually spoken to someone who bought into one of these scams. -- Consumed Crustacean (talk) 22:18, 23 March 2008 (UTC)
I do accept that having SP2 will help a lot. Kushal 13:00, 24 March 2008 (UTC)

[edit] Problems with connecting digital camera USB cable

I have problems connecting a USB cable to my Canon PowerShot S3 IS digital camera. I have the standard-sized USB plug end of the cable plugged in to my computer's USB port and the mini-sized USB plug end hanging free, ready to be plugged into the camera. When I plug the cable into the camera, the camera notices it by powering up. However, the computer does not recognise the camera. I have to twist the mini-sized plug toward the back of the camera to make the computer recognise it. If I let go of the plug, so that it moves back to its natural position, the computer stops recognising the camera. This is very annoying, as it usually means I have to keep twisting the plug with one hand when I transfer pictures from the camera. What is causing this, and how can I fix it? JIP | Talk 15:28, 22 March 2008 (UTC)

Loose connector on camera (fixable via Canon Service) or faulty USB cable (fixable by purchasing a new one). I think. --Ouro (blah blah) 17:06, 22 March 2008 (UTC)
I had the same problem with my cellphone charger. Moisture and dust are not good for cable connectors. I think I took my cellphone too many times into the bathroom. I cleaned the metal connectors with a toothpick (!) and hey presto it seems to work fine now. Sandman30s (talk) 12:20, 23 March 2008 (UTC)
I have an S3 IS too, though I've never had an issue like this. They are just standard 'mini-USB' cables, and nothing too proprietary, so they're easy to replace if need be, or if you've got any from other devices laying around. -- Consumed Crustacean (talk) 20:12, 23 March 2008 (UTC)

[edit] working physics problems using an artboard?

I want to collaborate with someone on some physics review problems, but scanning and emailing diagrams back and forth would be unweildy and time consuming. I know about oekaki and pictochat boards which let two people simulatanteously update the same picture in realtime which would be ideal; however I do not know where to go to find one of these oekaki or pictochat boards. The ideal board would have basic graphical functions like a straight line tool, the picture can be printed, and have an invite only section or something so that I can let in only the people who want to work on the physics problems. Does anyone have any idea where I can find an artboard like I described? Thanks in advance. 64.134.81.84 (talk) 16:09, 22 March 2008 (UTC)

Great idea, but I've never seen one. You might want to ask at the Miscellaneous desk for greater exposure. :D\=< (talk) 21:05, 22 March 2008 (UTC)
You can Sketchcast[1] or another thing I can't think of that lets you simultaneously have two people draw online for free. Mac Davis (talk) 00:54, 23 March 2008 (UTC)

[edit] Oh lord, he's got another CSS question

OK. Last one for awhile. I promise. I've tried to figure this one out but it's not coming to me.

I've been setting up this little menu:

<div id="menus">
                <ul>
                <li id="opt.0" class="unselected"><a href="about.html" target="content" onclick="javascript:select(0);">About</a></li>
                <li id="opt.1" class="unselected"><a href="research.html" target="content" onclick="javascript:select(1);">Research</a></li>
                <li id="opt.2" class="unselected"><a href="teaching.html" target="content" onclick="javascript:select(2);">Teaching</a></li>
                <li id="opt.3" class="unselected"><a href="contact.html" target="content" onclick="javascript:select(3);">Contact</a></li>
                </ul>
        </div>

Never mind that it uses frames at the moment (this is temporary, maybe. We'll see how it works out. I don't like 'em, but it might make life a lot easier in this case). The Javascript is just a simple little function — entirely aesthetic, just for kicks and giggles — that changes the class of the selected li from "unselected" to "selected" when you click on it.

The problem is, I can't seem to change the color of the link inside the list. I can change its background color no problem. But not the link color itself. WHY NOT?

Here's the CSS:

#menus a:hover, #menus li:hover, .selected {
        color: black;
        background-color: gold;
}

But the link color never changes to black. It stays its original color, white. I've tried using .selected a, .selected a:link, selected a.visited, .selected a:active, EVERYTHING I can think of, but it stubbornly stays white. I can change all sorts of other things (I can give .selected a a different background color, for example), but I can't change the text/link color. Note that it turns black when it is being hovered over, but it won't STAY black when it is "selected". The second that mouse isn't hovering over it anymore, it becomes white again. Even though the background color stays set as gold like it is supposed to.

I'm doing something wrong... but what is it? --Captain Ref Desk (talk) 19:58, 22 March 2008 (UTC)

You shouldn't need to use :link :visited or :active since the color would apply regardless of these conditions. I'd use the DOM inspector and the tools in the Web Developer addon to see what your javascript is actually doing and what styles are being applied :D\=< (talk) 20:38, 22 March 2008 (UTC)
I got it to work fine.. you can always work off my code if you can't figure out what's wrong with yours.
a {
        color: blue;
}
a.unselected { 
        color: black;
}
 
a.selected {
        color: white;
}
function selectLink(theid) {
        document.getElementById(theid).className = "selected";
}
<div id="menus">
                <ul>
                <li><a id="opt0" class="unselected" href="#" onclick="selectLink('opt0')">About</a></li>
                <li><a id="opt1" class="unselected" href="#" onclick="selectLink('opt1')">Research</a></li>
                <li><a id="opt2" class="unselected" href="#" onclick="selectLink('opt2')">Teaching</a></li>
                <li><a id="opt3" class="unselected" href="#" onclick="selectLink('opt3')">Contact</a></li>
                </ul>
</div>

Some problems that I had getting mine to work that you might want to watch out for... in your select() function are you concatenating "opt" to the argument you passed in? Notice that you're calling selectLink with just a number, and nothing has that ID. Remember to use single quotes like I did if you want to just pass in the full ID in string form. I moved the id and class over to the link tag but you shouldn't have to, it should be fine in the li tag. Also you probably want something in the selectLink function to deselect the other items when one is selected. Also if users are going to be able to navigate between About Research Teaching and Contact through in-text links in the other frame, it would probably be better to have the subpages report to the other frame (perhaps through the parent frameset; javascript and frames and security make a messy situation) that they've been opened instead of switching the styles on the actual click of the nav, since they might not have clicked the nav to get the that page. :D\=< (talk) 21:01, 22 March 2008 (UTC)

(after e.c.)Adding

#menus .selected a
{
        color: black;
}

worked when I tried your code. — Matt Eason (TalkContribs) 21:14, 22 March 2008 (UTC)

God, that's sooo simple and yet it works. Sigh. Thank you both! --Captain Ref Desk (talk) 21:35, 22 March 2008 (UTC)
As a small side note, I sometimes find setting the color of a elements to color: inherit is handy for this sort of thing. Also, if you're not already using it, Firebug is really good at sorting out CSS problems. Just my 2 cents. --h2g2bob (talk) 00:40, 23 March 2008 (UTC)
Well that would make it always black.. and you know you're setting both all links and everything with the class "selected" to be black.. I think you're trying to do a.selected :D\=< (talk) 03:16, 23 March 2008 (UTC)
Uh... no I'm not. It's a contextual selector so I'm targeting the last child of a hierarchy, not those elements individually, and the class is on li, not a. I'm talking about the original code, not yours, by the way. — Matt Eason (TalkContribs) 12:11, 23 March 2008 (UTC)