Xarwin Posted July 9, 2009 Share Posted July 9, 2009 Hey all. I was wandering around on google until I bounced upon this place and it looked ideal to ask a question about php. My question is as followed: Is it possible to show an image its 'alt' text instead of the image itself? For example to filter out images and showing the text only on a specific page. Many thanks in advance, > Xarwin Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/ Share on other sites More sharing options...
thebadbad Posted July 9, 2009 Share Posted July 9, 2009 If you have a HTML page with the images (and alt attributes), you can read in the source code with PHP, and filter out the alt attributes with regular expressions. Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-871990 Share on other sites More sharing options...
.josh Posted July 9, 2009 Share Posted July 9, 2009 Are you asking how to make a script to do that, as in, getting the contents of a page, altering the content and then display the page? Or are you talking about just seeing an image's alt text instead of the image while randomly surfing some xyz site? If it is the 2nd... that's not really something you would do with php. Disabling images, showing their alt text, etc.. stuff like that is usually built into the browser itself, or addons to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-872146 Share on other sites More sharing options...
Xarwin Posted July 9, 2009 Author Share Posted July 9, 2009 Hey, thanks for the answers. Yet I'll tell you the situation I'm in. I'm using smf myself but for the categories I'm using images for a better look. yet, the sitemap (or whatever called) is showing the image too, which doesn't look so nice. For example: PHP Freaks Forums > PHP Coding > PHP Help > filtering out images Say, for my forum that the PHP Coding is the category and the image. Instead of the text it is displayed as an image. I know that this is a complicated problem, yet I'm just curious if there is a way to get around it. Thanks in advance, - Xarwin Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-872252 Share on other sites More sharing options...
thebadbad Posted July 9, 2009 Share Posted July 9, 2009 To achieve that I believe you would have to edit the SMF source code somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-872274 Share on other sites More sharing options...
Xarwin Posted July 9, 2009 Author Share Posted July 9, 2009 Indeed, but the main problem is to change the image into the 'alt' text. - Xarwin Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-872338 Share on other sites More sharing options...
thebadbad Posted July 9, 2009 Share Posted July 9, 2009 You still need to edit how SMF handles the "bread crumbs" part, since it's currently using the forum images as is. You can't magically make the browser treat the images differently when they appear in the "bread crumbs". Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-872366 Share on other sites More sharing options...
Xarwin Posted July 10, 2009 Author Share Posted July 10, 2009 Yeah, I found them (someone pointed me on them). So, if there is a way to do so, on which kind of scripts should I search? Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-873042 Share on other sites More sharing options...
thebadbad Posted July 10, 2009 Share Posted July 10, 2009 If there is a way to do what? Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-873043 Share on other sites More sharing options...
Xarwin Posted July 10, 2009 Author Share Posted July 10, 2009 Showing the alt text of an image instead of the image itself. Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-873114 Share on other sites More sharing options...
thebadbad Posted July 10, 2009 Share Posted July 10, 2009 Do you want an example of what I described in my first post? I'm not quite sure what you want. Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-873119 Share on other sites More sharing options...
Xarwin Posted July 11, 2009 Author Share Posted July 11, 2009 Indeed, like what you described in your first post. Thanks. -Xarwin. Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-873342 Share on other sites More sharing options...
thebadbad Posted July 11, 2009 Share Posted July 11, 2009 <?php //source code. can be read in externally with e.g. file_get_contents() or cURL $code = '<img src="path/main.png" alt="Main forum" /> > <img src="path/php.png" alt="PHP help" />'; //replace image tags with their alt attribute $transformed = preg_replace('~<img[^>]+?alt="([^"]*)"[^>]*>~i', '$1', $code); echo $transformed; //Main forum > PHP help ?> Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-873405 Share on other sites More sharing options...
Xarwin Posted July 15, 2009 Author Share Posted July 15, 2009 Thanks for the code and sorry for the late response. I'm kinda busy these days but I appreciate your help and will try this out asap. - Xarwin Quote Link to comment https://forums.phpfreaks.com/topic/165344-filtering-out-images/#findComment-876049 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.