PHP使用正则表达式分离出HTML里我们所需的数据,封装到二维数组里

HTML代码(reg.html)

<TR id=J-item-1 class="J-item  " sizset="53" sizcache="3">
                                            <TD class=time>
                                                <P class=time-d>
                                                    2015.07.18
                                                </P>
                                            </TD>
                                            <TD class=memo sizset="53" sizcache="3">
                                                <A id=J-memo-trigger-1 class="record-icon icon-memo J-memo-trigger" href="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150718200040011100640031064039&amp;createDate=			20150718110348	&amp;bizType=D_TRANSFER"
                                                seed="memo-JMemoTrigger1" smartracker="on" jQuery17206151074297958363="11">
                                                </A>
                                                <DIV id=J-memo-cnt-1 class="fn-hide content-memo">
                                                    <DIV class=fn-clear>
                                                        <LABEL class=fn-left>
                                                            备注:
                                                        </LABEL>
                                                        <P class=memo-info>
                                                            还钱还钱~
                                                        </P>
                                                    </DIV>
                                                    <DIV class=security-tips>
                                                        请勿备注个人敏感信息
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                            <TD class=name sizset="54" sizcache="3">
                                                <P class=consume-title sizset="54" sizcache="3">
                                                    <A title=还钱还钱~ href="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150718200040011100640031064039"
                                                    target=_blank seed="consumeTitle-link" smartracker="on">
                                                        还钱还钱~
                                                    </A>
                                                </P>
                                            </TD>
                                            <TD class=amount>
                                                <SPAN class=amount-pay-in>
                                                    +2000.00
                                                </SPAN>
                                            </TD>
                                            <TD class=detail>
                                            </TD>
                                            <TD class=status>
                                                <P>
                                                    交易成功
                                                </P>
                                                <P class=ft-gray>
                                                </P>
                                            </TD>
                                            <TD class=action>
                                                <SELECT id=J-operation-select-1 class="fn-hide J-operation-select" seed="action-JOperationSelect1"
                                                smartracker="on">
                                                    <OPTION selected data-target="_blank" data-link="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150718200040011100640031064039">
                                                        详情
                                                    </OPTION>
                                                    <OPTION class=split seed="trade-memo" data-link="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150718200040011100640031064039&amp;createDate=			20150718110348
	&amp;bizType=D_TRANSFER"
                                                    data-tip="请勿备注个人敏感信息" rel-id="" data-action="edit-memo">
                                                        备注
                                                    </OPTION>
                                                    <OPTION seed="trade-delete" data-link="https://consumeprod.alipay.com:443/record/delete.json?record=			2015-07-18 11:03:48
	|20150718200040011100640031064039|D_TRANSFER"
                                                    rel-id="" data-action="delete" data-fund-change="true">
                                                        删除
                                                    </OPTION>
                                                </SELECT>
                                                <DIV id=J-operation-menu-1 class="operation-menu-trigger J-operation-menu-trigger"
                                                jQuery17206151074297958363="32">
                                                    <DIV class=current-item>
                                                        <SPAN class=item-text>
                                                            详情
                                                        </SPAN>
                                                        <SPAN class=icon-pull-down>
                                                            &nbsp;
                                                        </SPAN>
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                        </TR>
                                        <TR id=J-item-2 class="J-item split  " sizset="55" sizcache="3">
                                            <TD class=time>
                                                <P class=time-d>
                                                    2015.07.17
                                                </P>
                                            </TD>
                                            <TD class=memo sizset="55" sizcache="3">
                                                <A id=J-memo-trigger-2 class="record-icon icon-memo J-memo-trigger" href="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150717200040011100120030908656&amp;createDate=			20150717201424	&amp;bizType=D_TRANSFER"
                                                seed="memo-JMemoTrigger2" smartracker="on" jQuery17206151074297958363="16">
                                                </A>
                                                <DIV id=J-memo-cnt-2 class="fn-hide content-memo">
                                                    <DIV class=fn-clear>
                                                        <LABEL class=fn-left>
                                                            备注:
                                                        </LABEL>
                                                        <P class=memo-info>
                                                            私人借款
                                                        </P>
                                                    </DIV>
                                                    <DIV class=security-tips>
                                                        请勿备注个人敏感信息
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                            <TD class=name sizset="56" sizcache="3">
                                                <P class=consume-title sizset="56" sizcache="3">
                                                    <A title=私人借款 href="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150717200040011100120030908656"
                                                    target=_blank seed="consumeTitle-linkT1" smartracker="on">
                                                        私人借款
                                                    </A>
                                                </P>
                                            </TD>
                                            <TD class=amount>
                                                <SPAN class=amount-pay-out>
                                                    -2000.00
                                                </SPAN>
                                            </TD>
                                            <TD class=detail sizset="57" sizcache="3">
                                                <A onclick="return false;" class="J-amount-more mr-10 record-icon icon-detail J-details-trigger"
                                                href="https://consumeprod.alipay.com:443/record/funditem.json?bizType=D_TRANSFER&amp;bizInNo=20150717200040011100120030908656&amp;gmtBizCreate=			20150717201424	"
                                                seed="trade-details" jQuery17206151074297958363="25">
                                                </A>
                                            </TD>
                                            <TD class=status>
                                                <P>
                                                    交易成功
                                                </P>
                                                <P class=ft-gray>
                                                </P>
                                            </TD>
                                            <TD class=action>
                                                <SELECT id=J-operation-select-2 class="fn-hide J-operation-select" seed="action-JOperationSelect2"
                                                smartracker="on">
                                                    <OPTION selected data-target="_blank" data-link="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150717200040011100120030908656">
                                                        详情
                                                    </OPTION>
                                                    <OPTION class=split seed="trade-memo" data-link="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150717200040011100120030908656&amp;createDate=			20150717201424
	&amp;bizType=D_TRANSFER"
                                                    data-tip="请勿备注个人敏感信息" rel-id="" data-action="edit-memo">
                                                        备注
                                                    </OPTION>
                                                    <OPTION seed="trade-delete" data-link="https://consumeprod.alipay.com:443/record/delete.json?record=			2015-07-17 20:14:24
	|20150717200040011100120030908656|D_TRANSFER"
                                                    rel-id="" data-action="delete" data-fund-change="true">
                                                        删除
                                                    </OPTION>
                                                </SELECT>
                                                <DIV id=J-operation-menu-2 class="operation-menu-trigger J-operation-menu-trigger"
                                                jQuery17206151074297958363="35">
                                                    <DIV class=current-item>
                                                        <SPAN class=item-text>
                                                            详情
                                                        </SPAN>
                                                        <SPAN class=icon-pull-down>
                                                            &nbsp;
                                                        </SPAN>
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                        </TR>
                                        <TR id=J-item-3 class="J-item  " sizset="58" sizcache="3">
                                            <TD class=time>
                                                <P class=time-d>
                                                    2015.07.17
                                                </P>
                                            </TD>
                                            <TD class=memo>
                                            </TD>
                                            <TD class=name sizset="58" sizcache="3">
                                                <P class=consume-title sizset="58" sizcache="3">
                                                    <A title=转账 href="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150717200040011100200030848594"
                                                    target=_blank seed="consumeTitle-linkT2" smartracker="on">
                                                        转账
                                                    </A>
                                                </P>
                                            </TD>
                                            <TD class=amount>
                                                <SPAN class=amount-pay-in>
                                                    +2000.00
                                                </SPAN>
                                            </TD>
                                            <TD class=detail>
                                            </TD>
                                            <TD class=status>
                                                <P>
                                                    交易成功
                                                </P>
                                                <P class=ft-gray>
                                                </P>
                                            </TD>
                                            <TD class=action>
                                                <SELECT id=J-operation-select-3 class="fn-hide J-operation-select" seed="action-JOperationSelect3"
                                                smartracker="on">
                                                    <OPTION selected data-target="_blank" data-link="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150717200040011100200030848594">
                                                        详情
                                                    </OPTION>
                                                    <OPTION class=split seed="trade-memo" data-link="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150717200040011100200030848594&amp;createDate=			20150717201338
	&amp;bizType=D_TRANSFER"
                                                    data-tip="请勿备注个人敏感信息" rel-id="" data-action="edit-memo">
                                                        备注
                                                    </OPTION>
                                                    <OPTION seed="trade-delete" data-link="https://consumeprod.alipay.com:443/record/delete.json?record=			2015-07-17 20:13:38
	|20150717200040011100200030848594|D_TRANSFER"
                                                    rel-id="" data-action="delete" data-fund-change="true">
                                                        删除
                                                    </OPTION>
                                                </SELECT>
                                                <DIV id=J-operation-menu-3 class="operation-menu-trigger J-operation-menu-trigger"
                                                jQuery17206151074297958363="38">
                                                    <DIV class=current-item>
                                                        <SPAN class=item-text>
                                                            详情
                                                        </SPAN>
                                                        <SPAN class=icon-pull-down>
                                                            &nbsp;
                                                        </SPAN>
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                        </TR>
                                        <TR id=J-item-4 class="J-item split  " sizset="59" sizcache="3">
                                            <TD class=time>
                                                <P class=time-d>
                                                    2015.07.15
                                                </P>
                                            </TD>
                                            <TD class=memo>
                                            </TD>
                                            <TD class=name sizset="59" sizcache="3">
                                                <P class=consume-title sizset="59" sizcache="3">
                                                    <A title=提现-快速提现 href="https://shenghuo.alipay.com/transfercore/withdraw/withdrawDetail.htm?billNo=20150715200040011100120030294289"
                                                    target=_blank seed="consumeTitle-linkT3" smartracker="on">
                                                        提现-快速提现
                                                    </A>
                                                </P>
                                            </TD>
                                            <TD class=amount>
                                                <SPAN class=amount-pay-out>
                                                    -2000.00
                                                </SPAN>
                                            </TD>
                                            <TD class=detail>
                                            </TD>
                                            <TD class=status>
                                                <P>
                                                    交易成功
                                                </P>
                                                <P class=ft-gray>
                                                </P>
                                            </TD>
                                            <TD class=action>
                                                <SELECT id=J-operation-select-4 class="fn-hide J-operation-select" seed="action-JOperationSelect4"
                                                smartracker="on">
                                                    <OPTION selected data-target="_blank" data-link="https://shenghuo.alipay.com/transfercore/withdraw/withdrawDetail.htm?billNo=20150715200040011100120030294289">
                                                        详情
                                                    </OPTION>
                                                    <OPTION class=split seed="trade-memo" data-link="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150715200040011100120030294289&amp;createDate=			20150715181828
	&amp;bizType=D_TRANSFER"
                                                    data-tip="请勿备注个人敏感信息" rel-id="" data-action="edit-memo">
                                                        备注
                                                    </OPTION>
                                                    <OPTION seed="trade-delete" data-link="https://consumeprod.alipay.com:443/record/delete.json?record=			2015-07-15 18:18:28
	|20150715200040011100120030294289|D_TRANSFER"
                                                    rel-id="" data-action="delete" data-fund-change="true">
                                                        删除
                                                    </OPTION>
                                                    <OPTION seed="download-receipt" data-target="_self" data-link="https://consumeprod.alipay.com:443/voucher/produce.htm?voucherType=receipt&amp;requestString=D_TRANSFER%3B20150715200040011100120030294289%3B1436955508000">
                                                        电子回单
                                                    </OPTION>
                                                </SELECT>
                                                <DIV id=J-operation-menu-4 class="operation-menu-trigger J-operation-menu-trigger"
                                                jQuery17206151074297958363="41">
                                                    <DIV class=current-item>
                                                        <SPAN class=item-text>
                                                            详情
                                                        </SPAN>
                                                        <SPAN class=icon-pull-down>
                                                            &nbsp;
                                                        </SPAN>
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                        </TR>
                                        <TR id=J-item-5 class="J-item  " sizset="60" sizcache="3">
                                            <TD class=time>
                                                <P class=time-d>
                                                    2015.07.15
                                                </P>
                                            </TD>
                                            <TD class=memo>
                                            </TD>
                                            <TD class=name sizset="60" sizcache="3">
                                                <P class=consume-title sizset="60" sizcache="3">
                                                    <A title=转账 href="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150715200040011100200030203901"
                                                    target=_blank seed="consumeTitle-linkT4" smartracker="on">
                                                        转账
                                                    </A>
                                                </P>
                                            </TD>
                                            <TD class=amount>
                                                <SPAN class=amount-pay-in>
                                                    +3000.00
                                                </SPAN>
                                            </TD>
                                            <TD class=detail>
                                            </TD>
                                            <TD class=status>
                                                <P>
                                                    交易成功
                                                </P>
                                                <P class=ft-gray>
                                                </P>
                                            </TD>
                                            <TD class=action>
                                                <SELECT id=J-operation-select-5 class="fn-hide J-operation-select" seed="action-JOperationSelect5"
                                                smartracker="on">
                                                    <OPTION selected data-target="_blank" data-link="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150715200040011100200030203901">
                                                        详情
                                                    </OPTION>
                                                    <OPTION class=split seed="trade-memo" data-link="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150715200040011100200030203901&amp;createDate=			20150715174951
	&amp;bizType=D_TRANSFER"
                                                    data-tip="请勿备注个人敏感信息" rel-id="" data-action="edit-memo">
                                                        备注
                                                    </OPTION>
                                                    <OPTION seed="trade-delete" data-link="https://consumeprod.alipay.com:443/record/delete.json?record=			2015-07-15 17:49:51
	|20150715200040011100200030203901|D_TRANSFER"
                                                    rel-id="" data-action="delete" data-fund-change="true">
                                                        删除
                                                    </OPTION>
                                                </SELECT>
                                                <DIV id=J-operation-menu-5 class="operation-menu-trigger J-operation-menu-trigger"
                                                jQuery17206151074297958363="44">
                                                    <DIV class=current-item>
                                                        <SPAN class=item-text>
                                                            详情
                                                        </SPAN>
                                                        <SPAN class=icon-pull-down>
                                                            &nbsp;
                                                        </SPAN>
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                        </TR>
                                        <TR id=J-item-6 class="J-item split  " sizset="61" sizcache="3">
                                            <TD class=time>
                                                <P class=time-d>
                                                    2015.07.15
                                                </P>
                                            </TD>
                                            <TD class=memo>
                                            </TD>
                                            <TD class=name sizset="61" sizcache="3">
                                                <P class=consume-title sizset="61" sizcache="3">
                                                    <A title="淘宝购物-PUKKA折叠迷你电动滑板车 成人电动车代驾代步锂电动自行车电瓶车" href="https://lab.alipay.com/consume/queryTradeDetail.htm?tradeNo=2015071521001001120211456668"
                                                    target=_blank seed="consumeTitle-linkT5" smartracker="on">
                                                        淘宝购物-PUKKA折叠迷你电动滑板车 成人电动车代驾代步锂电动自行车电瓶车
                                                    </A>
                                                </P>
                                            </TD>
                                            <TD class=amount>
                                                <SPAN class=amount-pay-out>
                                                    -2270.00
                                                </SPAN>
                                            </TD>
                                            <TD class=detail sizset="62" sizcache="3">
                                                <A onclick="return false;" class="J-amount-more mr-10 record-icon icon-detail J-details-trigger"
                                                href="https://consumeprod.alipay.com:443/record/funditem.json?bizType=TRADE&amp;bizInNo=2015071521001001120211456668&amp;gmtBizCreate=			20150715174853	"
                                                seed="trade-details" jQuery17206151074297958363="27">
                                                </A>
                                            </TD>
                                            <TD class=status>
                                                <P>
                                                    等待确认收货
                                                </P>
                                                <P class=ft-gray>
                                                </P>
                                            </TD>
                                            <TD class=action>
                                                <SELECT id=J-operation-select-6 class="fn-hide J-operation-select" seed="action-JOperationSelect6"
                                                smartracker="on">
                                                    <OPTION selected seed="confirm-goods" data-target="_blank" data-link="https://lab.alipay.com/consume/queryTradeDetail.htm?actionName=CONFIRM_GOODS&amp;tradeNo=2015071521001001120211456668">
                                                        确认收货
                                                    </OPTION>
                                                    <OPTION seed="trade-refund" data-target="_blank" data-link="https://lab.alipay.com/consume/queryTradeDetail.htm?actionName=APPLY_REFUND&amp;tradeNo=2015071521001001120211456668">
                                                        退款
                                                    </OPTION>
                                                    <OPTION disabled seed="long-time" data-link="javascript:void(0)" data-tip="您可以联系卖家为您延长确认收货时间">
                                                        延长时间
                                                    </OPTION>
                                                    <OPTION seed="trade-detail" data-target="_blank" data-link="https://lab.alipay.com/consume/queryTradeDetail.htm?tradeNo=2015071521001001120211456668">
                                                        详情
                                                    </OPTION>
                                                    <OPTION class=split seed="trade-memo" data-link="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=2015071521001001120211456668&amp;createDate=			20150715174853
	&amp;bizType=TRADE"
                                                    data-tip="请勿备注个人敏感信息" rel-id="" data-action="edit-memo">
                                                        备注
                                                    </OPTION>
                                                    <OPTION seed="trade-delete" data-link="https://consumeprod.alipay.com:443/record/delete.json?record=			2015-07-15 17:48:53
	|2015071521001001120211456668|TRADE"
                                                    rel-id="" data-action="delete" data-fund-change="true">
                                                        删除
                                                    </OPTION>
                                                </SELECT>
                                                <DIV id=J-operation-menu-6 class="operation-menu-trigger J-operation-menu-trigger operation-menu-trigger-hot"
                                                jQuery17206151074297958363="47">
                                                    <DIV class=current-item>
                                                        <SPAN class=item-text>
                                                            确认收货
                                                        </SPAN>
                                                        <SPAN class=icon-pull-down>
                                                            &nbsp;
                                                        </SPAN>
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                        </TR>
                                        <TR id=J-item-7 class="J-item  " sizset="63" sizcache="3">
                                            <TD class=time>
                                                <P class=time-d>
                                                    2015.07.14
                                                </P>
                                            </TD>
                                            <TD class=memo sizset="63" sizcache="3">
                                                <A id=J-memo-trigger-7 class="record-icon icon-memo J-memo-trigger" href="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150714200040011100120030144108&amp;createDate=			20150714230734	&amp;bizType=D_TRANSFER"
                                                seed="memo-JMemoTrigger7" smartracker="on" jQuery17206151074297958363="21">
                                                </A>
                                                <DIV id=J-memo-cnt-7 class="fn-hide content-memo">
                                                    <DIV class=fn-clear>
                                                        <LABEL class=fn-left>
                                                            备注:
                                                        </LABEL>
                                                        <P class=memo-info>
                                                            美满幸福
                                                        </P>
                                                    </DIV>
                                                    <DIV class=security-tips>
                                                        请勿备注个人敏感信息
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                            <TD class=name sizset="64" sizcache="3">
                                                <P class=consume-title sizset="64" sizcache="3">
                                                    <A title=美满幸福 href="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150714200040011100120030144108"
                                                    target=_blank seed="consumeTitle-linkT6" smartracker="on">
                                                        美满幸福
                                                    </A>
                                                </P>
                                            </TD>
                                            <TD class=amount>
                                                <SPAN class=amount-pay-out>
                                                    -6666.66
                                                </SPAN>
                                            </TD>
                                            <TD class=detail sizset="65" sizcache="3">
                                                <A onclick="return false;" class="J-amount-more mr-10 record-icon icon-detail J-details-trigger"
                                                href="https://consumeprod.alipay.com:443/record/funditem.json?bizType=D_TRANSFER&amp;bizInNo=20150714200040011100120030144108&amp;gmtBizCreate=			20150714230734	"
                                                seed="trade-details" jQuery17206151074297958363="29">
                                                </A>
                                            </TD>
                                            <TD class=status>
                                                <P>
                                                    交易成功
                                                </P>
                                                <P class=ft-gray>
                                                </P>
                                            </TD>
                                            <TD class=action>
                                                <SELECT id=J-operation-select-7 class="fn-hide J-operation-select" seed="action-JOperationSelect7"
                                                smartracker="on">
                                                    <OPTION selected data-target="_blank" data-link="https://shenghuo.alipay.com/send/queryTransferDetail.htm?tradeNo=20150714200040011100120030144108">
                                                        详情
                                                    </OPTION>
                                                    <OPTION class=split seed="trade-memo" data-link="https://consumeprod.alipay.com:443/record/editMemo.htm?bizInNo=20150714200040011100120030144108&amp;createDate=			20150714230734
	&amp;bizType=D_TRANSFER"
                                                    data-tip="请勿备注个人敏感信息" rel-id="" data-action="edit-memo">
                                                        备注
                                                    </OPTION>
                                                    <OPTION seed="trade-delete" data-link="https://consumeprod.alipay.com:443/record/delete.json?record=			2015-07-14 23:07:34
	|20150714200040011100120030144108|D_TRANSFER"
                                                    rel-id="" data-action="delete" data-fund-change="true">
                                                        删除
                                                    </OPTION>
                                                </SELECT>
                                                <DIV id=J-operation-menu-7 class="operation-menu-trigger J-operation-menu-trigger"
                                                jQuery17206151074297958363="51">
                                                    <DIV class=current-item>
                                                        <SPAN class=item-text>
                                                            详情
                                                        </SPAN>
                                                        <SPAN class=icon-pull-down>
                                                            &nbsp;
                                                        </SPAN>
                                                    </DIV>
                                                </DIV>
                                            </TD>
                                        </TR>

PHP代码(reg.php)

<?php
header("content-type:text/html;charset=utf-8;");
$str = file_get_contents(‘./reg.html‘);
$arr = array();

//匹配出每一行的数据的html字符串
preg_match_all(‘/<TR id=J-item-\d{1}[\s\S]*?<\/TR>/‘,$str,$revals);

for($i=0;$i<count($revals[0]);$i++){
    $t = $revals[0][$i];
    //匹配交易时间
    preg_match(‘/\b\d{4}\.\d{2}\.\d{2}\b/‘, $t,$a);
    $a = $a[0];
    //交易类型
    preg_match(‘/<A title=[\s\S]*?<\/A>/‘, $t,$b);
    $b = preg_split("/[><]+/", $b[0]);
    $b = trim($b[2]);
    //匹配金额
    preg_match(‘/[-|+]\d{0,}\.\d{2}/‘, $t,$c);
    $c = $c[0];
    //交易状态
    preg_match(‘/<P>[\s\S]*?<\/P>/‘, $t,$d);
    $d = preg_split("/[><]+/", $d[0]);
    $d = trim($d[2]);
    //封装到数组里
    $tmp = array(‘交易时间‘ => $a, ‘交易类型‘=> $b,‘交易金额‘=> $c,‘交易状态‘=> $d);
    array_push($arr, $tmp);
    //echo $a .‘<br>‘.$b.‘<br>‘.$c.‘<br>‘.$d;
    //echo ‘<hr >‘;
}
echo ‘<pre>‘;
print_r($arr);
echo ‘</pre>‘;

运行结果截图

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-01 23:56:10

PHP使用正则表达式分离出HTML里我们所需的数据,封装到二维数组里的相关文章

二维数组里,根据数组字段为条件,进行总体排序(二维排序)

1 <?php 2 /** 3 * 二维数组根据某个字段排序 4 * 功能:按照用户的年龄倒序排序 5 * @author ruxing.li 6 */ 7 header('Content-Type:text/html;Charset=utf-8'); 8 $arrUsers = array( 9 array( 10 'id' => 1, 11 'name' => '张三', 12 'age' => 25, 13 ), 14 array( 15 'id' => 2, 16 '

Python学习笔记 之 递归、二维数组顺时针旋转90&#176;、正则表达式

递归.二维数组顺时针旋转90°.正则表达式 1.   递归算法是一种直接或间接调用自身算法的过程. 特点: 递归就是在过程或函数里调用自身 明确的递归结束条件,即递归出口 简洁,但是不提倡 递归次数多容易造成栈溢出 要求: 每次调用递归规模上有所减小 前一次为后一次做准备 规模较小时必须直接给出解答而不再进行递归调用 例子:递归实现二分法 1 def searchMyData(mydate,a1): 2 mid = int(len(mydate)/2) 3 if mid >= 1: 4 if m

Python 迭代器&amp;生成器,装饰器,递归,算法基础:二分查找、二维数组转换,正则表达式,作业:计算器开发

本节大纲 迭代器&生成器 装饰器  基本装饰器 多参数装饰器 递归 算法基础:二分查找.二维数组转换 正则表达式 常用模块学习 作业:计算器开发 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )等类似公式后,必须自己解析里面的(),+,-,*,/符号和公式,运算后得出结果,结果必须与真实的计算器所得出的结果一致 迭代器&

求出二维数组每一行的平均值

1 //二维数组每行输出平均值 2 //2017.3.7 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 void Rand(int arr[][100], int n); 7 void OutputAvg(int arr[][100], int n); 8 int main() 9 { 10 int arr[100][100]; 11 int n = 10; 12 int sum = 0; 13 //随机初始化数组 14 Rand(a

44.从键盘输入12个数存入二维数组a[3][4]中,编写程序求出最大元素的值及它所在的行号和列号

//1.建立二维数组 //2.运用循环,将内容输入到数组中 //3.求出最大元素,并输出行号和列号 #include<iostream> using namespace std; int main() { int a[3][4]; int Max=0;//赋值之前需要先置为0 cout<<"please input 12 numbers: "<<endl; for(int i=0;i<3;i++)//嵌套循环,用于向二维数组中输入内容 { fo

c语言题目:找出一个二维数组的“鞍点”,即该位置上的元素在该行上最大,在该列上最小。也可能没有鞍点

1 //题目:找出一个二维数组的"鞍点",即该位置上的元素在该行上最大,在该列上最小.也可能没有鞍点. 2 // 3 #include "stdio.h" 4 #include <stdlib.h> 5 int main() 6 { 7 int i,j,k,hang=1,lie=1; 8 printf("输入行"); 9 scanf("%d",&hang); 10 printf("输入列"

如何用一层for循环打印出一个二维数组

常规通过两层for循环可以比较轻松打印二维数组. 代码如下: #include <stdio.h> #define ROWS 3 #define COLS 3 int main() { int a[ROWS][COLS]={1,2,3,4,5,6,7,8,9}; for(int i=0;i<ROWS;i++) { for(int j=0;j<COLS;j++) printf("%d ",a[i][j]); printf("\n"); } re

用二维数组打印出杨辉三角

用二维数组打印出杨辉三角 首先你得知道二位数组和熟练二位数组,再次你得知道杨辉三角的规律! 相信能知道这个的,你已经掉了半只脚在这个坑了,不说废话直接上... 针对Javascript掌握基础的: 在电脑输入cmd命令打开控制器先要创建node'.js的环境: 你得把这个文件夹和你的js文件放在一起! js代码如下: 1 let readline = require("readline-sync"); 2 console.log("请输入杨辉三角的行数:"); 3

二维数组循环求出最大子数组

package shengcheng; import java.util.Scanner; import org.junit.Test; public class ErweiXunhuan { @Test public void fun() { int [][]a=new int[4][8]; Scanner write=new Scanner(System.in); for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { a[i][j]=write.nex