Asked  7 Months ago    Answers:  5   Viewed   42 times

I want to receive an array that contains all the h1 tag values from a text

Example, if this where the given input string:

<p>random text</p>
<h1>title number two!</h1>

I need to receive an array containing this:

titles[0] = 'hello',
titles[1] = 'title number two!'

I already figured out how to get the first h1 value of the string but I need all the values of all the h1 tags in the given string.

I'm currently using this to receive the first tag:

function getTextBetweenTags($string, $tagname) 
  $pattern = "/<$tagname ?.*>(.*)</$tagname>/";
  preg_match($pattern, $string, $matches);
  return $matches[1];

I pass it the string I want to be parsed and as $tagname I put in "h1". I didn't write it myself though, I've been trying to edit the code to do what I want it to but nothing really works.

I was hoping someone could help me out.

Thanks in advance.



you could use simplehtmldom:

function getTextBetweenTags($string, $tagname) {
    // Create DOM from string
    $html = str_get_html($string);

    $titles = array();
    // Find all tags 
    foreach($html->find($tagname) as $element) {
        $titles[] = $element->plaintext;
Wednesday, March 31, 2021
answered 7 Months ago
SELECT userID, userName, userProfession, userPic FROM tbl_users WHERE userProfession = "Teacher" ORDER BY userID DESC

is what you need.

Saturday, May 29, 2021
answered 5 Months ago

Try with actual PHPDoc for your getById() where you specify dynamic type (e.g. @return static or @return $this).

That's the most common way of providing such "this class and its' children" typehint.

Another possible option is kind of the same .. but using PHP 7.1 functionality (so no PHPDoc blocks).

Try using self as return type instead of Model. I mean here:

public static function getById(string $id) : ?Model {

use this instead:

public static function getById(string $id) : ?self {

But for this one you should use PhpStorm 2017.2 EAP build as 2017.1.x has issues with that (see as an example).

Saturday, May 29, 2021
answered 5 Months ago

CURLOPT_VERBOSE should actually show the details. If you're looking for the response body content, you can also use CURLOPT_RETURNTRANSFER, curl_exec() will then return the response body.

If you need to inspect the request body, CURLOPT_VERBOSE should give that to you but I'm not totally sure.

In any case, a good network sniffer should give you all the details transparently.


$curlOptions = array(
    CURLOPT_STDERR => $verbose = fopen('php://temp', 'rw+'),

$url = "";
$handle = curl_init($url);
curl_setopt_array($handle, $curlOptions);
$content = curl_exec($handle);
echo "Verbose information:n", !rewind($verbose), stream_get_contents($verbose), "n";
echo $content;


Verbose information:
* About to connect() to port 80 (#0)
*   Trying
* connected
* Connected to ( port 80 (#0)
> GET /questions/tagged/java HTTP/1.1
Accept: */*

< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
< Date: Wed, 14 Mar 2012 19:27:53 GMT
< Content-Length: 59110
* Connection #0 to host left intact

<!DOCTYPE html>


    <title>Newest &#39;java&#39; Questions - Stack Overflow</title>
    <link rel="shortcut icon" href="">
    <link rel="apple-touch-icon" href="">
    <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
Thursday, July 29, 2021
answered 3 Months ago

Based on your screenshot of Settings (Preferences on Mac) | Editor | Language Injections.

Please delete 3rd language injection rule from the bottom (the one for "div" -- that has "IDE" in Scope column).

That rule injects HTML into div tag which tells IDE to treat all other code (even PHP) inside such tag as HTML/plain text.

Thursday, August 5, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :