Joined October 2012
·
Posted to
RegEx to find <img/> tags missing alt attributes
over 1 year
ago
@ryanartecona
I ended up using XPath.
$html = file_get_contents($filename);
$dom = new DOMDocument();
@$dom->loadHtml($html);
$xpath = new DOMXPath($dom);
$entries = $xpath->query("//a[not(img) and not(contains(concat(' ', @class, ' '), ' standard_link '))]");
if($entries->length > 0){
echo '<ul><li style="font-weight: bold;">' . $filename . '</li><ol>';
}
foreach ($entries as $entry) {
$array[] = $dom->saveHTML($entry);
}
if(isset($array))
foreach($array as $value)
echo '<li>' . htmlspecialchars($value) . '</li>';
echo '</ol></ul>';
Posted to
Reset a form
over 1 year
ago
You'd use my function if you already had a populated form where textboxes had values and checkboxes were checked (with the attribute set) and you wanted to reset those to be blank and unchecked.
Posted to
RegEx to find <img/> tags missing alt attributes
over 1 year
ago
First of all, thank you. I've changed it to look for links/anchors that are missing a class attribute.
<a(\s(?!class)([\w-])+=([\"\'])[^\"\']+\3)\s*\/?>
-Could it be extended to look for links/anchors missing a particular class such as 'standard_link'? The problem is further complicated by the fact that there could be multiple classes defined. I know regex shouldn't really be used with html but I want to use it with the program grepwin to look through my PHP code to make sure I've added a class to all my links.
Achievements
87 Karma
2,843 Total ProTip Views
Walrus
The walrus is no stranger to variety. Use at least 4 different languages throughout all your repos
Honey Badger
Have at least one original Node.js-specific repo
Forked
Have a project valued enough to be forked by someone else
Charity
Fork and commit to someone's open source project in need
I've recently integrated gulp into the workflow we use in our development team at work and as such I have created a gulp-starter GitHub repo (albeit a little advanced) which might be of interest to you: https://github.com/uofa/gulp-starter