Jump to content

filtering out images


Xarwin

Recommended Posts

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.