0

So I have this code:

<a style="color:white" id="randomNo">Hello</a>;

I am using jQuery to get the value of it by using:

$('#randomNo').text();

Is there a way to get the value ("Hello") in PHP?

Ben
  • 8,894
  • 7
  • 44
  • 80
wobsoriano
  • 12,348
  • 24
  • 92
  • 162

2 Answers2

1

@FewFlyBy here look (Note: this is just a example of using js var in php).

<div id="foo">Click Me</div>    
    $("#foo").on('click', function(event) {

        event.preventDefault();

        var randomNo= $('#randomNo').text();
        // Ajax.
        $.ajax({
            url: "SAMPLE.php",
            type: "post",
            data: {
                   randomNo: randomNo
            },
            success: function(){
                alert("success");
            },
            error:function(){
                alert("failure");
            }
        });
    });

on SAMPLE.php get the value from $_POST['randomNo'];

This is just a sample. if want want you can send your value to php page like above.

Hassan Ali
  • 593
  • 1
  • 8
  • 26
1

Hi You have to extract the anchor tag then textContent will help you to fetch the text of anchor tag

Here is the sample stuff

$link = "<a href='test.php'>tester</a>";
$dom = new domdocument;
$dom->loadHTML($link);
foreach ($dom->getElementsByTagName("a") as $a) {
    echo $a->textContent, "\n";
    echo $a->getAttribute("href"), "\n";
}

Hope it helps.

Vignesh Pichamani
  • 7,950
  • 22
  • 77
  • 115