Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7607969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:48:02+00:00 2026-05-31T00:48:02+00:00

I want to access a custom attribute that I added to some elements in

  • 0

I want to access a custom attribute that I added to some elements in an HTML file, here’s an example of the littleBox="somevalue" attribute

<div id="someId" littleBox="someValue">inner text</div>

The Following doesn’t work:

foreach($html->find('div') as $element){
 echo $element;
 if(isset($element->type)){
 echo $element->littleBox;
   }
}

I saw an article with a similar problem, but I couldn’t replicate it for some reason. Here is what I tried:

function retrieveValue($str){
if (stripos($str, 'littleBox')){//check if element has it
$var=preg_split("/littleBox=\"/",$str);
//echo $var[1];
$var1=preg_split("/\"/",$var[1]);
echo $var1[0];
}
else
return false;
}

When ever I call the retrieveValue() function, nothing happens. Is $element (in the first PHP example above) not a string? I don’t know if I missed something but it’s not returning anything.

Here’s the script in it’s entirety:

<?php
require("../../simplehtmldom/simple_html_dom.php");

if (isset($_POST['submit'])){

$html = file_get_html($_POST['webURL']);

// Find all images 
foreach($html->find('div') as $element){
    echo $element;
   if(isset($element->type)!= false){
    echo retrieveValue($element);
   }
}
}


function retrieveValue($str){
if (stripos($str, 'littleBox')){//check if element has it
$var=preg_split("/littleBox=\"/",$str);
//echo $var[1];
$var1=preg_split("/\"/",$var[1]);
return $var1[0];
}
else
return false;
}

?>

<form method="post">
Website URL<input type="text" name="webURL">
<br />
<input type="submit" name="submit">
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:48:04+00:00Added an answer on May 31, 2026 at 12:48 am

    Have you tried:

    $html->getElementById("someId")->getAttribute('littleBox');
    

    You could also use SimpleXML:

    $html = '<div id="someId" littleBox="someValue">inner text</div>';
    $dom = new DOMDocument;
    $dom->loadXML($html);
    $div = simplexml_import_dom($dom);
    echo $div->attributes()->littleBox;
    

    I would advice against using regex to parse html but shouldn’t this part be like this:

    $str = $html->getElementById("someId")->outertext;
    $var = preg_split('/littleBox=\"/', $str);
    $var1 = preg_split('/\"/',$var[1]);
    echo $var1[0];
    

    Also see this answer https://stackoverflow.com/a/8851091/1059001

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a custom AuthorizeAttribute class as described here: Override Authorize Attribute
I want to be able to access custom URLs with apache httpclient. Something like
I want to access a MySQL database directly from JavaScript code in an HTML
I want to associate custom data to a Type, and retrieve that data in
I'm trying to make a set of custom tags that encapsulate form elements (markup
I have made a custom Attribute here named AAtribute, and for instance a class
I've got a custom control that inherits from Panel . At Load-time, I want
I want to know is there any way to add a custom attribute to
I want to access the joomla environment in my plugin and added these line
I have a custom attribute, inside the constructor of my custom attribute I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.